MySQL 修改时区

来自姬鸿昌的知识库
Jihongchang讨论 | 贡献2022年8月30日 (二) 05:57的版本 (建立内容为“=== 1.确认当前时区 === <syntaxhighlight lang="powershell"> mysql> show variables like "%time_zone%"; +------------------+--------+ | Variable_name | Valu…”的新页面)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

1.确认当前时区

mysql> show variables like "%time_zone%";
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone |        |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set, 1 warning (0.00 sec)

上面是修改前的


2. 停止 MySQL Server 服务

3.编辑 my.ini 配置文件

......
# Path to the database root
datadir=C:/ProgramData/MySQL/MySQL Server 5.7/Data

default-time_zone = '+8:00'
......

在 datadir 后面插入一行 "default-time_zone = '+8:00'"


4.启动 MySQL Server 服务

5.确认时区变更生效

mysql> show variables like "%time_zone%";
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone |        |
| time_zone        | +08:00 |
+------------------+--------+
2 rows in set, 1 warning (0.00 sec)