一、方法
首先要进入 MySQL 服务,输入 mysql
发现报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)。
换成以下命令:
$ mysql -u root -p
然后输入数据库密码进入数据库:

image
查看时区:
SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
如果是中国标准时间, 会输出 08:00:00。
查看 MySQL 当前时间、当前时区:
select curtime();
show variables like "%time_zone%";

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

image
再次查看时区,发现 time_zone 已经修改了:

image
不放心就退出重启 MySQL 服务再查看一下时区:
$ systemctl start mysqld

image
二、参考
转自:https://www.jianshu.com/p/e94d78eee13f