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