标签:pretty glob ring time var like ret 查看 one
mysql> show variables like ‘%time_zone%‘;
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | CST -07:00|
+------------------+--------+
2 rows in set (0.00 sec) 这里CST -07:00代表北美时间
mysql默认使用的SYSTEM时区,即EST时区,查询相关资料可知,EST时区要比北京时间(东八区)慢13个小时,在数据库中的表现即为:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2017-03-09 21:24:39 |
+---------------------+
1 row in set (0.00 sec)
那我们怎么修改,有两种方法,一种是临时的,一种是长久的。
一:通过sql命令临时修改
# 设置全局时区 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)
# 刷新权限使设置立即生效 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like ‘%time_zone%‘;
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | EST |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
二:修改my.cnf实现永久修改
vi /etc/mysql/my.cnf
然后在mysqld下边的配置中添加一行:
default-time_zone = ‘+8:00‘
然后重启mysql
service mysql restart
标签:pretty glob ring time var like ret 查看 one
原文地址:https://www.cnblogs.com/michaelcnblogs/p/12242482.html