First you need to check the current time zone of mysql, use 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
default-time-zone=timezone
under [mysqld] to modify the time zone. For example:
default-time-zone = '+8:00'
After modification, remember to restart msyql
Be sure to add it under [mysqld], otherwise unknown variable 'default-time- will appear zone=+8:00'
2 In addition, you can also modify it online through the command line
set time_zone = timezone 比如北京时间(GMT+0800) set time_zone = '+8:00'; 如下: mysql> set time_zone='+8:00'; 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)
3 Then verify the time zone through select now()
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() | +---------------------+ | 2013-08-05 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() | +---------------------+ | 2013-08-05 02:35:43 | +---------------------+ 1 row in set (0.00 sec)
The above is to modify the time zone of MySQL, involving the parameter time_zone. For more related content, please pay attention to PHP Chinese Net (www.php.cn)!