Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report