- Mysql默认使用系统的时区
mysql> show global variables like '%time%zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | |
| time_zone | SYSTEM | # 表明使用系统时间
+------------------+--------+
2 rows in set, 1 warning (0.17 sec)
mysql>
- 在Mysql配置文件中设置时区
修改完配置之后,需要重启MySQL服务,否则不生效。
[mysqld]
# 设置默认时区
# default-time-zone='+08:00'
修改之后在终端查看是否生效
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set, 1 warning (0.03 sec)
mysql>
# 设置新的时区
mysql> SET TIME_ZONE = '-6:00';
Query OK, 0 rows affected (0.00 sec)
# 查看设置的时区是否生效
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | |
| time_zone | -06:00 |
+------------------+--------+
2 rows in set, 1 warning (0.00 sec)
mysql>