First you need to check the current time zone of MySQL with the Time_zone parameter
[HTML]View Plaincopy print?
- MySQL> Show variables like '%time_zone% ';
- +------------------+--------+
- | variable_name | Value |
- +------------------+--------+
- | System_time_zone | CST |
- | Time_zone | SYSTEM |
- +------------------+--------+
- 2 rows in Set (0.00 sec)
1 can be modified by my.cnf
Under [mysqld], add
Default-time-zone=timezone
To modify the time zone. Such as:
Default-time-zone = ' the ' "
When you're done, remember to restart MSYQL.
Note must be added under [mysqld], otherwise it will appear unknown variable ' default-time-zone=+8:00 '
2 can also be modified online via the command line
[HTML]View Plaincopy print?
- Set Time_zone = timezone
- For example, Beijing (gmt+0800)
- Set Time_zone = ' A ', as follows:
- MySQL> Set time_zone=';
- 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 Verify the time zone by using select Now ()
[HTML]View Plaincopy print?
- MySQL> Show variables like '%time_zone% ';
- +------------------+--------+
- | variable_name | Value |
- +------------------+--------+
- | System_time_zone | CST |
- | <span style="color: #3366ff;" >time_zone | +08:00 </span>|
- +------------------+--------+
- 2 rows in Set (0.00 sec)
- MySQL> select now ();
- +---------------------+
- | Now () |
- +---------------------+
- | <span style="color: #3333ff;" >2013-08-05 10:35:31 </span>|
- +---------------------+
- 1 row in Set (0.00 sec)
- MySQL> <span style="color: #ff0000;" >set </span><span style="color: #ff0000;" >time_zone=' +0:00 ';
- </span>query OK, 0 rows Affected (0.00 sec)
[HTML]View Plaincopy print?
- mysql> show variables like '%time_zone% ';
- +------------------+--------+
- | variable_name | value |
- +------------------+ --------+
- | system_time_zone | cst |
- |span style= color:# ff0000; " > time_zone | +00:00 </span>|
- +------------------+--------+
- 2 rows in set (0.00 sec)
[HTML]View Plaincopy print?
- MySQL> select now ();
- +---------------------+
- | Now () |
- +---------------------+
- | <span style="color: #ff0000;" >2013-08-05 02:35:43 </span>|
- +---------------------+
- 1 row in Set (0.00 sec)
Modify the MySQL time zone, involving parameter Time_zone (RPM)