MySQL method summary for modifying time zone

Source: Internet
Author: User
Tags cst time mysql command line

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

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.