Mysql Modify the time zone method summary _mysql

Source: Internet
Author: User
Tags cst time current time time zones mysql in mysql command line

The example in this article summarizes the method of MySQL modifying time zone. Share to everyone for your reference, specific as follows:

Description: Here is a summary of the three ways to modify the MySQL time zone.

Method One: Dynamic modification via MySQL command line mode

1.1 View MySQL current time, current timezone

> select Curtime ();  #或select now () can also be
+-----------+
| curtime () |
+-----------+
| 15:18:10 |
+-----------+
> show variables like "%time_zone%";
+------------------+--------+
| Variable_name  | Value |
+------------------+--------+
| system_time_zone | CST  |
| Time_zone    | SYSTEM |
+------------------+--------+
2 rows in Set (0.00 sec)
#time_zone说明mysql使用system的时区, system_time_ Zone Description system uses CST time zone

1.2 Modifying time zones

> Set Global time_zone = ' +8:00 '; # #修改mysql全局时区为北京时间, our East 8
> Set time_zone = ' +8:00 '; # #修改当前会话时区
> Flush privileges; #立即生效

Method Two: Modify the time zone by modifying the MY.CNF configuration file

# vim/etc/my.cnf # #在 the [mysqld] area plus
default-time_zone = ' +8:00 '
#/etc/init.d/mysqld Restart # #重启mysql使新时区生效

Method Three: If not convenient to restart MySQL, but also want to temporarily resolve the time zone problem, you can initialize MySQL in PHP or other languages when initializing MySQL time zone

Here, take PHP for example, use under mysql_connect ():

mysql_query ("SET time_zone = ' +8:00 '")

This allows you to change the time zone without restarting. However, some of the system functions of MySQL are still not available as: Now (). This sentence, still can't understand.

More information about MySQL interested readers can view the site topics: "MySQL Log operation skills Daquan", "MySQL Transaction operation skills Summary", "MySQL stored process skills encyclopedia", "MySQL database lock related skills summary" and "MySQL commonly used function large summary"

I hope this article will help you with the MySQL database meter.

Related Article

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.