This article mainly introduces the method of MySQL to modify time zone, summarizes and analyzes three common MySQL time zone modification techniques, including command line mode, configuration file mode and code mode, the need for friends can refer to the following
Method One: Dynamic modification via MySQL command line mode
1.1 View MySQL current time, current time zone
> select Curtime (); #或select now () can also +-----------+| Curtime () |+-----------+| 15:18:10 |+-----------+> show variables like "%time_zone%"; +------------------+--------+| Variable_name | Value |+------------------+--------+| System_time_zone | CST | | time_zone | SYSTEM |+------------------+--------+2 rows in Set (0.00 sec) #time_zone说明mysql使用system的时区, system_time_ Zone description system using CST time zone
1.2 Modifying the time zone
> Set global time_zone = '; # #修改mysql全局时区为北京时间, where we are located in the East 8 district > Set time_zone = ' "; # #修改当前会话时区 > Flush privileges; #立即生效
Method Two: Modify the time zone by modifying the MY.CNF configuration file
# vim/etc/my.cnf # #在 the [mysqld] area plus default-time_zone = '/etc/init.d/mysqld ' # restart # #重启mysql使新时区生效
Method Three: If it is not convenient to restart MySQL, and want to temporarily solve the time zone problem, you can initialize MySQL time zone by PHP or other language
Here, take PHP for example, under mysql_connect () use:
mysql_query ("SET time_zone = '" ")
This allows you to change the time zone when you are guaranteed not to reboot. But some of MySQL's system functions are still not available as: Now (). This sentence, still do not understand.
MySQL method summary for modifying time zone