MySQL修改数据库时区

2020-06-27  本文已影响0人  Kevin_8424

一:通过sql命令临时修改

--查看数据库时区设置
mysql> show variables like "%time_zone%";
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | UTC |
| time_zone | SYSTEM |
+------------------+--------+
--修改当前会话时区,退出msql后 time_zone 会恢复成修改前的值
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 | UTC |
| time_zone | +08:00 |
+------------------+--------+

—-修改全局会话时区
mysql> set global time_zone = '+8:00';
mysql> set time_zone = '+8:00';
mysql> flush privileges;

二:修改my.cnf实现永久修改

vi /etc/mysql/my.cnf

然后在mysqld下边的配置中添加一行:

default-time_zone = '+8:00'

然后重启mysql

service mysql restart
上一篇下一篇

猜你喜欢

热点阅读