First, you need to view the current MySQL time zone, with the time_zone Parameter
Mysql> show variables like '% time_zone % '; + ------------------ + -------- + | variable_name | value | + ------------------ + -------- + | system_time_zone | CST | time_zone | system | + ------------------ + -------- + 2 rows in SET (0.00 Sec)
1 You can modify my. CNF
Add under [mysqld]
Default-time-zone = timezone
To modify the time zone. For example:
Default-time-zone = '+ 8:00'
After modification, remember to restart msyql.
Note that you must add it under [mysqld]. Otherwise, the unknown variable 'default-time-zone = + 8:00 'will appear'
2. You can also modify it online through the command line.
Set time_zone = timezone, for example, Beijing time (GMT + 0800) set time_zone = '+'; below: mysql> set time_zone = '+'; query OK, 0 rows affected (0.00 Sec) mysql> show variables like '% time_zone % '; + rows + -------- + | variable_name | value | + ---------------- + -------- + | system_time_zone | CST | time_zone | + 08:00 | + ---------------- + -------- + 2 rows in SET (0.00 Sec)
3. Use select now () to verify the time zone.
mysql> show variables like '% time_zone % '; + ------------------ + -------- + | variable_name | value | + ------------------ + -------- + | system_time_zone | CST | time_zone | + 08:00 | + ------------------ + -------- + 2 rows in SET (0.00 Sec) mysql> select now (); + ------------------- + | now () | + --------------------- + | 10:35:31 | + ------------------- + 1 row in SET (0.00 Sec) mysql> set time_zone = '+ 0: 00 '; query OK, 0 rows affected (0.00 Sec)
Mysql> show variables like '% time_zone %'; + ------------------ + -------- + | variable_name | value | + ------------------ + -------- + | system_time_zone | CST |Time_zone | + 00:00| + ------------------ + -------- + 2 rows in SET (0.00 Sec)
Mysql> select now (); + ------------------- + | now () | + --------------------- + |02:35:43| + --------------------- + 1 row in SET (0.00 Sec)
References:
Http://dev.mysql.com/doc/refman/5.7/en/time-zone-leap-seconds.html