MySQL 8.0.12 時區設定和修改
阿新 • • 發佈:2018-12-18
1.查詢系統支援當前的時區設定: mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec) mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | SYSTEM | +------------------+--------+ 2 rows in set (0.00 sec) 2.修改時區設定: 方法1:寫入到配置檔案需要重啟mysql例項: [mysqld] default-time-zone=timezone 修改為 default-time-zone = '+8:00' 方法2:線上修改和檢視: mysql> set time_zone='+8:00'; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +08:00 | +------------------+--------+ 2 rows in set (0.01 sec) --通過now() 檢視: mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +08:00 | +------------------+--------+ 2 rows in set (0.01 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-08-28 16:08:38 | +---------------------+ 1 row in set (0.00 sec) mysql> set time_zone='+0:00'; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +00:00 | +------------------+--------+ 2 rows in set (0.01 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-08-28 08:09:12 | +---------------------+ 1 row in set (0.00 sec) --自MySQL 8.0 GA版本開始支援將引數寫入並且持久化: mysql> set persist time_zone='+0:00'; --針對application 可以設定: jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&serverTimezone=UTC --結論: mysql> set time_zone='+8:00'; 和time_zone='system'是等同的,預設為系統時間。