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.