MySQL Time Zone modification method summary, mysql Time Zone Summary

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

MySQL Time Zone modification method summary, mysql Time Zone Summary

This example summarizes how MySQL modifies the time zone. We will share this with you for your reference. The details are as follows:

Note:Here we will summarize three methods for modifying the mysql time zone.

Method 1: Dynamic Modification in mysql Command Line Mode

1.1 view the current mysql time, current time zone

> Select curtime (); # or 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 indicates that mysql uses the system time zone, and system_time_zone indicates that system uses the CST time zone.

1.2 modify the time zone

> Set global time_zone = '+'; # change the mysql global Time Zone to Beijing time, that is, the East 8 zone where we are located> set time_zone = '+ '; # modify the current session time zone> flush privileges; # take effect immediately

Method 2: Modify the time zone by modifying the my. cnf configuration file.

# Vim/etc/my. cnf # Add default-time_zone = '+' #/etc/init in the [mysqld] region. d/mysqld restart # restart mysql to make the new zone take effect

Method 3: If you do not need to restart mysql and want to temporarily solve the time zone problem, you can use php or other languages to initialize the mysql time zone during mysql initialization.

Here, we use php as an example and use it in mysql_connect:

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

In this way, you can change the time zone without restarting. However, some system functions of mysql still cannot be used, such as: now (). This sentence cannot be understood.

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.