Home > Database > Mysql Tutorial > Modify the time zone of MySQL, involving the parameter time_zone

Modify the time zone of MySQL, involving the parameter time_zone

黄舟
Release: 2017-02-17 11:54:54
Original
2132 people have browsed it

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)
Copy after login



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)
Copy after login


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)
Copy after login
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +00:00 |
+------------------+--------+
2 rows in set (0.00 sec)
Copy after login
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2013-08-05 02:35:43 |
+---------------------+
1 row in set (0.00 sec)
Copy after login


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)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template