Home > Database > Mysql Tutorial > body text

How to change the time zone in mysql

青灯夜游
Release: 2021-12-02 15:48:21
Original
8987 people have browsed it

Mysql method to modify the time zone: 1. In the mysql command line mode, execute the "set global time_zone = 'time zone information'" command; 2. In the "my.cnf" file, search and Just modify the value of the "default-time_zone" item to the required time zone.

How to change the time zone in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Method 1: Dynamically modify through the mysql command line mode

1. Check the current time of mysql and the current time zone

select curtime();  
#或
select now()
Copy after login

How to change the time zone in mysql

show variables like “%time_zone%”;
2 rows in set (0.00 sec)
Copy after login

#time_zone indicates that mysql uses the system's time zone, system_time_zone indicates that the system uses the CST time zone

2. Modify the time zone

set global time_zone = ‘+8:00’; ##修改mysql全局时区为北京时间,即我们所在的东8区
set time_zone = ‘+8:00’; ##修改当前会话时区
flush privileges; #立即生效
Copy after login

Method 2: Pass Modify the my.cnf configuration file to modify the time zone

default-time_zone = ‘+8:00’
Copy after login

After the modification is completed, restart the database server.

Method 3: Use PHP's mysql_connect() function (temporarily solve the time zone problem)

mysql_query(“SET time_zone = ‘+8:00’”)
Copy after login

This way you can change the time zone without restarting. However, some system functions of mysql still cannot be used, such as: now(). I still can't understand this sentence.

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to change the time zone in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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