Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set mysql time Zone in php

Shulou Source: shulou.com Published: 2022-06-03 11:35:51 09月14日 Update

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!

Tags: Time zone method code command time content file article configuration value interest available through guys buddies hours that is data databases more servers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft MariaDB OPPO Reno macOS