1. 程式人生 > >MySQL Config--參數system_time_zone和參數time_zone

MySQL Config--參數system_time_zone和參數time_zone

sof init mps sql pan onf oba 檢查 ans

全局參數system_time_zone
系統時區,在MySQL啟動時會檢查當前系統的時區並根據系統時區設置全局參數system_time_zone的值。

The system time zone. When the server starts, it attempts to determine the time zone of the host machine automatically and uses it to set thesystem_time_zone system variable. The value does not change thereafter.

全局參數time_zone

用來設置每個連接會話的時區,默認為system時,使用全局參數system_time_zone的值。

The current time zone. This variable is used to initialize the time zone for each client that connects. By default, the initial value of this is ‘SYSTEM‘ (which means, “use the value of system_time_zone”).

參數log_timestamps
用於設置Error Log/Genaral Log/Slow Log這三種日誌的時間信息。


有效值為UTC(默認)和SYSTEM(本地系統時區),當設置為system時,會使用參數system_time_zone的值。

修改參數time_zone

# 啟動命令
--default-time-zone=timezone
# 配置文件
default-time-zone=timezone
# 運行期間
set global time_zone = timezone

set global time_zone=+8:00
set global time_zone=Asia/Shanghai

查看操作系統時區

## 使用date命令
date 
+"%Z %z" date -R ## 使用timedatectl timedatectl|grep "Timezone" ## 查看文件 /etc/timezone cat /etc/timezone

如果無法修改操作系統時區,又希望數據庫使用其他時區,則可以使用參數time_zone來修改。

MySQL Config--參數system_time_zone和參數time_zone