MySQL时区设置

查看mysql时区

mysql> show variables like '%time_zone%';   
+------------------+--------+   
| Variable_name    | Value  |   
+------------------+--------+   
| system_time_zone | CST    |    
| time_zone        | SYSTEM |    
+------------------+--------+   
2 rows in set (0.00 sec)   

设置时区参数

方式1.命令行修改

set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区
set time_zone = '+8:00'; ##修改当前会话时区
flush privileges; #立即生效

方式2.修改my.cnf文件

# vim /etc/my.cnf
##在[mysqld]区域中加上
default-time_zone = '+8:00'
# /etc/init.d/mysqld restart ##重启mysql使新时区生效
posted @ 2021-09-28 18:03  可可逗豆  阅读(574)  评论(0)    收藏  举报