Check the time zone database
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 use the SYSTEM default time zone, namely EST time zone, relevant information can be seen, EST time zone than in Beijing (East eight districts) slow 13 hours, manifested in the database that is:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2017-03-09 21:24:39 |
+---------------------+
1 row in set (0.00 sec)
Then how do we modify, there are two ways, one is temporary, one is long.
A: temporary modification by sql command
# 设置全局时区 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)
Two: to achieve a permanent modification to modify my.cnf
vi /etc/mysql/my.cnf
Then add the following line to the mysqld configuration:
default-time_zone = '+8:00'
Then restart the mysql
service mysql restart