system_time_zone參數值由來


參考文檔:

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_system_time_zone

 

無意間注意到 system_time_zone 參數值經常是 UTC,CST,WIB 等.

查看幫助文檔,這個參數取自操作系統時區,經過查看,取的是當前操作系統時區文件數據

[root@node1 ~]# cat /etc/localtime 
TZif'pZip ~h^JGg%_

CST-8

 

如果將時區文件替換為 UTC 時區,重啟數據庫后,則 system_time_zone 參數值是 UTC

[root@node1 ~]# cp /usr/share/zoneinfo/UTC /etc/localtime 
cp: overwrite ‘/etc/localtime’? yes
[root@node1 ~]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service

mysql> show global variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | UTC    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

 

問題延伸:

tzselect 命令並不能更換操作系統時區,只告訴你選擇的時區的寫法。

參考:https://blog.csdn.net/csdnhnma/article/details/100044630

 

time_zone參數默認不能設置為 UTC 之類的關鍵字,需要導入時間數據。

mysql> set time_zone='UTC';
ERROR 1298 (HY000): Unknown or incorrect time zone: 'UTC'
mysql> exit

 

 

[root@node1 ~]# mysql_tzinfo_to_sql /usr/share/zoneinfo |mysql -uroot -p mysql
Enter password: 
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.

 

mysql> set time_zone='UTC';
Query OK, 0 rows affected (0.00 sec)

mysql> 

 

mysql> set time_zone='Asia/Jakarta';    ---這個是印尼時區
Query OK, 0 rows affected (0.00 sec)

mysql> select now();                   ----now() 結果已經比北京時間早一小時
+---------------------+
| now()               |
+---------------------+
| 2021-09-08 15:06:11 |
+---------------------+
1 row in set (0.00 sec)

 

 

參考:https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM