Time zone adjustment for MySQL and PHP

Source: Internet
Author: User
Tags time zones
I remember when I got the WIKI website during my internship, the time displayed on the server was Greenwich Mean Time (eight hours slower than Beijing time,

I remember when I got the WIKI website during my internship, the time displayed on the server was Greenwich Mean Time (eight hours slower than Beijing time,

I remember when I got the WIKI website during my internship, the time displayed on the server was Greenwich Mean Time (eight hours slower than Beijing time, data collection on the Internet has not been resolved. Later, I found some information on the Internet and finally solved the problem. The problem was originally set in PHP.

The solution is written here. Note that the modification is C: \ windows \ php. the INI file is enough. It turns out that we have been searching for this file in the PHP installation directory. Of course, it is wrong. In addition, most of the following content comes from the Internet, haha

You can set the time zone of the PHP script in php. ini to 'Asia/Shanghai. However, the shared VM itself does not have the permission to modify php. ini. This should be added to the public part of the program.

Ini_set ('date. timezone ', 'Asia/Shanghai ');

Modify php. ini settings dynamically. Then you can test whether the time is correct:
Var_dump (date ());

If the local time of the server is correct, the problem can be solved. Appendix: PHP 5.1 and above provide special functions to modify the corresponding time zone:

Date_default_timezone_set ('Asia/Shanghai ');

We recommend that you use this function because it is more common. Corresponding to 'Asia/Shanghai', other available mainland time zones include Asia/Chongqing, Asia/Shanghai, and Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence). Hong Kong and Taiwan regions are available: asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, and Taipei in sequence), Singapore: Asia/Singapore, and other available values are: etc/GMT-8, Singapore, Hongkong, PRC; foreigners seem to have missed Beijing.

MySQL time zone problems:

Method 1
1. Use mysql command mode
Mysql> select CURTIME ();
Or
Mysql> select now ();
Check whether the current time is correct. You can see that mysql is currently using the time zone.

2. Change the time zone in the mysql command line.
Mysql> SET time_zone = '+'; # when this is Beijing, we are located in the east 8 Zone
Mysql> flush privileges; # effective immediately

At this time, the mysql time zone has been changed correctly, and the Shanghai time is used for both the time zone and the system time zone.

#### This method seems to be only available on the terminal. After exiting the terminal, the time will change to the original one. It seems that you can only restart mysql.

3. Restart mysql. At this time, mysql will actively read the system time.

Method 2:
If the mysql database can be restarted and restarted directly, mysql should be able to actively read the system time immediately. If not, change the mysql configuration file (mysql. cnf)

In the [mysqld] area of my. cnf, add
Default-time_zone = '+ 8:00' # This is Beijing time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.