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
This example summarizes how MySQL modifies the time zone. Share to everyone for your reference, as follows:
Description: Here is a summary of three ways to modify the MySQL time zone.
Method One: Dynamic modification via MySQL command line mode
1.1 View MySQL current time, current time zone
> SelectCurtime (); #或select now () can also+-----------+|Curtime ()|+-----------+| the: -:Ten |+-----------+>Show variables like"%Time_zone%";+------------------+--------+|Variable_name|Value|+------------------+--------+|System_time_zone|Cst||Time_zone|SYSTEM|+------------------+--------+2Rowsinch Set(0.00sec) #time_zone说明mysql使用system的时区, System_time_zone description system uses CST time zone
1.2 Modifying the time zone
> Set = ' the ' # #修改mysql全局时区为北京时间, where we're in the East 8 area > Set = ' the ' ; # #修改当前会话时区 > privileges; #立即生效
Method Two: Modify the time zone by modifying the MY.CNF configuration file
/etc/my.cnf # #在[mysqld] area plus default- = ' the ' /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='" ")
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.
More interested in MySQL related content readers can view the topic: "MySQL Log operation skills Daquan", "MySQL Transaction skills summary", "MySQL Storage process skills Daquan", "MySQL database lock related skills summary" and "MySQL Common function Summary"
I hope this article is useful for MySQL database.
MySQL method summary for modifying time zone