参考:https://www.cnblogs.com/shiqiangqiang/p/8393662.html
1,查看当前时间,时区
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-07-12 15:02:48 | +---------------------+ 1 row in set (0.00 sec)
mysql> show variables like "%time_zone%"; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | UTC | | time_zone | SYSTEM | +------------------+--------+ 2 rows in set (0.01 sec)
#time_zone说明mysql使用system的时区,system_time_zone说明system使用UTC时区
2,修改时区
mysql> set global time_zone = '+8:00'; Query OK, 0 rows affected (0.00 sec) mysql> set time_zone = '+8:00'; Query OK, 0 rows affected (0.00 sec)
3,设置重启永久生效
修改配置文件
/etc/my.cnf
[mysqld] default-time_zone = '+8:00'