MySQL time zone settings

Source: Internet
Author: User
Mysql_query (& quot; SETtime_zone = '+ 8:00' & quot;) ordie ('Time zone setting failed. please contact the administrator! ');

The MySQL time zone is the server's time zone by default.
You can run the following command to view

View the time zone

SQL code
. Mysql> show variables like '% time_zone % ';
. + ------------------ + -------- +
. | Variable_name | Value |
. + ------------------ + -------- +
. | System_time_zone | CST |
. | Time_zone | SYSTEM |
. + ------------------ + -------- +
. 2 rows in set (0.00 sec)

Note: If the value of time_zone is SYSTEM, it indicates that its time zone is the same as that of the operating SYSTEM.

You can modify my. cnf

Add under [mysqld]

Default-time-zone = timezone

To modify the time zone. For example:

Default-time-zone = '+ 8:00'

Remember to restart msyql.

Note that you must add it under [mysqld]. Otherwise, the error message "unknown variable 'default-time-zone = + 8:00 '" appears.

You can also run the set time_zone = timezone command.

For example, Beijing time (GMT + 0800)

Set time_zone = '+ 8:00 ';

> In the PHP program>

Date_default_timezone_set ('prc') or die ('Time zone setting failed. please contact the administrator! ');

> Query or use a database>

// Once the database is connected, it is followed by the MySQL time code.
Mysql_query ("SET time_zone = '+ 8:00'") or die ('Time zone setting failed. please contact the administrator! ');

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.