Home >Database >Mysql Tutorial >How to change the time zone in mysql

How to change the time zone in mysql

青灯夜游
青灯夜游Original
2021-12-02 15:48:219008browse

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

How to change the time zone in mysql

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

#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; #立即生效

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

default-time_zone = ‘+8:00’

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’”)

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!

Statement:
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