Get the App
SLTechnology News&Howtos  ›  Database  › 

How to modify the mysql time zone

Shulou Source: shulou.com Published: 2022-05-31 12:48:52 09月29日 Update

Editor to share with you how to modify the mysql time zone, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

The method to modify the mysql time zone: 1, to view the current time zone and time of MySQL; 2, to modify the time zone by modifying the parameters of environment variables or by modifying the my.cnf configuration file to modify the time zone.

This article operating environment: Windows7 system, Mysql5.7.14 version, Dell G3 computer.

Summary of the method of modifying time Zone by MySQL

Problem phenomenon:

The date in the database appears fine, but it is found that the time difference is 13 hours after the call through JSP. Upon inquiry, this problem is caused by the default time zone setting of MySQL.

The specific investigation and operation methods are as follows:

View the current time zone and time of MySQL

> show variables like "% time_zone%"; # View time zone

# time_zone indicates that mysql uses the time zone of system, while system_time_zone indicates that system uses CST time zone

> select curtime (); # View time > select now (); # View date + time

II. Modify the time zone

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

> set global time_zone ='+ 8 flush privileges; 00 hours; # # modify the global time zone of mysql to Beijing time, that is, our East 8 Zone > set time_zone ='+ 8 set time_zone 00 hours; # # modify the current session time zone > flush privileges; # effective immediately

In the actual operation, this modification is not successful, showing 0 row (s) affected

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

# vim / etc/my.cnf add: default-time_zone ='+ 8mysqld'to the [mysqld] area

After the modification is completed, you need to restart the startup MySQL, and the configuration takes effect.

The above is all the contents of the article "how to modify the mysql time zone". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Time zone time method environment article configuration content parameters variables files dates problems success not much deviation global region most actual hour Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Huawei NVidia OPPO Reno