How to set mysql time Zone in php
This article mainly introduces how to set the mysql time zone in php. It is very detailed and has a certain reference value. Friends who are interested must read it!
Php mysql time zone setting method: 1, execute the "show variables like'% time_zone%';" command; 2, by modifying the mysql configuration file my.cnf or my.ini to set the time zone; 3, through the "set time_zone" command to set the time zone.
MySQL time zone setting method
The MySQL time zone defaults to the server's time zone, which is 8 hours different from that in China.
View method
SQL code
Mysql > show variables like'% time_zone%'
+-+-+ | Variable_name | Value | +-+ | system_time_zone | CST | | time_zone | SYSTEM | +-+
Modify time zone method
Method 1:
You can modify the mysql configuration file my.cnf or my.ini
Add default-time-zone=timezone under [mysqld] to modify the time zone.
Such as:
Default-time-zone ='+ 8VR 00'
Restart msyql
Be sure to add it under [mysqld], otherwise unknown variable 'default-time-zone=+8:00' will appear.
Method 2:
Through the command set time_zone = timezone
such as
Beijing time (GMT+0800) set time_zone ='+ 8 pst time (GMT-08:00) set time_zone ='- 8 pst 00'
SQL code
Mysql > set time_zone ='+ 8RV 00'
In program development, once the database is connected, it can be followed by the code to change the MySQL time.
Mysql_query ("SET time_zone ='+ 8mysql 00'"); the above is all the content of the article "how to set the mysql time zone in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!