Mysql method to modify the time zone: 1. Dynamically modify it in the mysql command line mode; 2. Modify the time zone by modifying the my.cnf configuration file; 3. Initialize the mysql time zone when initializing mysql through php or other languages. .
The operating environment of this article: Windows 7 system, mysql version 8.0, Dell G3 computer.
How to modify the time zone in mysql?
Several ways to modify the time zone in mysql
Instructions:
The following records several methods for modifying the MySQL time zone.
Specific:
Method 1: Dynamically modify through the mysql command line mode
1.1 Check the current time of mysql and the current time zone
> select curtime(); #或select now()也可以 +-----------+ | 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说明system使用CST时区
1.2 Modify the time zone
> set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区 > set time_zone = '+8:00'; ##修改当前会话时区 > flush privileges; #立即生效
Method 2: Modify the time zone by modifying the my.cnf configuration file
# vim /etc/my.cnf ##在[mysqld]区域中加上 default-time_zone = '+8:00' # /etc/init.d/mysqld restart ##重启mysql使新时区生效
Method 3: If it is inconvenient Restart mysql and want to temporarily solve the time zone problem. You can initialize the mysql time zone when initializing mysql through php or other languages.
Here, taking php as an example, use mysql_query("SET time_zone = ' 8" under mysql_connect() :00′”).
This allows you to change the time zone without restarting. However, some system functions of mysql still cannot be used, such as: now(). I still can't understand this sentence.
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to change the time zone in mysql. For more information, please follow other related articles on the PHP Chinese website!