首先需要查看mysql的当前时区,用time_zone参数
mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | SYSTEM | +------------------+--------+
第一步
mysql> set global time_zone = '+08:00'; set time_zone = '+08:00';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
第二部
修改的/etc/my.cnf的
default-time-zone = '+08:00'
第三部,重启mysql服务器,不重启是不会生效的.
[root@iZbp15d0fgh0v1wwql5r4uZ etc]# init.d/mysql restart
修改成功后是:
mysql> show variables like '%time_zone%'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +08:00 | +------------------+--------+
第二部很重要,不然怎么都设置无效