This article mainly introduces the method of MySQL to modify the time zone, summarizes and analyzes three common MySQL time zone modification techniques, including command line mode, configuration file method and code method. Friends who need it can refer to
Method 1: Modify dynamically through mysql command line mode
1.1 View mysql current time and current time zone
> select curtime(); # or 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 indicates that mysql uses the time zone of system, and system_time_zone indicates that system uses CST time zone
1.2 Modify time zone
1 2 3 |
|
Method 2: Modify the time zone by modifying the my.cnf configuration file
1 2 3 |
|
Method 3: If it is inconvenient to restart mysql and you want to temporarily solve the time zone problem, you can initialize the mysql time zone when mysql is initialized through php or other languages
Here, take php as an example, and use it under mysql_connect():
1 |
|
This allows you to change the time zone without restarting. But some system functions of mysql still cannot be used, such as now(). This sentence still cannot be understood.