Get the App
SLTechnology News&Howtos  ›  Database  › 

What if the time difference of MySQL insertion is eight hours?

Shulou Source: shulou.com Published: 2022-05-31 21:52:01 10月03日 Update

The purpose of this article is to share with you what to do with the MySQL insertion time difference of eight hours. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Solve the problem of MySQL insertion time difference of eight hours

In general, several parameters need to be added to jdbc url. Most blogs give tutorials with useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC parameters.

The configuration result is: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

I used to use serverTimezone=UTC to solve time zone problems, but I didn't know it was a panacea until I stepped on a small hole today.

First, insert a record normally.

It is found that the recording time of the database is not the same as the local time.

The first one: check the time in mysql

Log in to mysql with mysql-u username-p password in cmd first

Enter select now ()

View MySQL time

If the time is the same as your local current time

It shows that there is no problem with the time of mysql, but the problem lies in the time of java.

Try changing the jdbc url parameter to serverTimezone=Asia/Shanghai.

Second: if the query mysql time is inconsistent with the local time, use the following statement to set the mysql time zone

Show variables like'% time_zone%'; / / query the current time zone set global time_zone='+8:00'; / / add + 8 hours to the standard time zone, that is, East Zone 8 time flush privileges; # takes effect immediately

Final test effect

Thank you for reading! This is the end of the article on "what to do with the MySQL insertion time difference of eight hours". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Time hour time zone problem time difference parameter how to do consistent content more article query good practical this is not Admiral blog password pit effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi vpn Docker Shulou Technology