Home > Database > Mysql Tutorial > How to change mysql time zone

How to change mysql time zone

藏色散人
Release: 2021-12-02 11:38:46
Original
8899 people have browsed it

How to modify the mysql time zone: 1. Check the current time zone and time of MySQL; 2. Modify the time zone by modifying the environment variable parameters or modify the time zone by modifying the my.cnf configuration file.

How to change mysql time zone

The operating environment of this article: Windows 7 system, Mysql version 5.7.14, Dell G3 computer.

How to modify the mysql time zone?

Summary of how to modify the time zone in MySQL

Problem phenomenon:

The date in the database is displayed normally, but after calling it through JSP, it is found that the time is offset by 13 hours. After inquiry, this problem is caused by MySQL's default time zone setting.

The specific troubleshooting and operation methods are as follows:

1. Check the current time zone and time of MySQL

> show variables like "%time_zone%";  #查看时区
Copy after login

# time_zone indicates that mysql uses the system's time zone, system_time_zone indicates that the system uses the CST time zone

> select curtime();  #查看时间
> select now();  #查看日期+时间
Copy after login

  

2. Modify the time zone

Method 1: Modify the time zone by modifying the environment variable parameters

> set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区
> set time_zone = '+8:00'; ##修改当前会话时区
> flush privileges; #立即生效
Copy after login

During the actual operation, this modification was not successful, showing 0 row(s) affected

Method 2: By modifying my.cnf Configuration file to modify the time zone

# vim /etc/my.cnf
在[mysqld]区域中加上:default-time_zone = '+8:00'
Copy after login

After the modification is completed, you need to restart MySQL for the configuration to take effect.

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to change mysql time zone. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template