一、 mysql -uroot -p 登陆
1. set global time_zone = '+8:00'; #全局
2. set time_zone = '+8:00'; # 当前会话
2. flush privileges; # 生效
二、 my.cnf
locate my.cnf
mysql --help | grep my.cnf
[mysqld]
default-time-zone='+8:00'
三、Django
LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True # USE_TZ = True
四、对于容器环境,,可将配置文件拷贝到宿主机,改好后再拷贝到容器中覆盖原有的配置文件。
docker cp my.cnf mysql-container-id:/etc/mysql/my.cnf
service mysqld restart (stop/ start /status)
chkconfig --list | grep mysql 查询Sysv服务
systemctl list-unit-files | grep mysql 查询 systemd 服务
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> set time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)