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)