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

Method One: Dynamic modification via MySQL command line mode

1.1 View MySQL current time, current time zone

> select Curtime ();  #或select now () can also +-----------+| 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 using CST time zone

1.2 Modifying the time zone

> Set global time_zone = '; # #修改mysql全局时区为北京时间, where we are located in the East 8 district > Set time_zone = ' "; # #修改当前会话时区 > 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 = '/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 time_zone = '" ")

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.

MySQL method summary for modifying time zone

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.