Problem Description:
Using springmvc as the framework, when inserting (updating) data into the database, it is found that the data in the time format is automatically reduced by 14 hours.
For example: I INSERT INTO test_table (id, name, birthday) VALUES(1, 'chen', '2017-12-12 15:00:00')
After inserting into the database through the code, it is found that the time of the birthday field is not '2017-12-12 15:00:00', but '2017-12-12 01:00:00'.
(Note: Execute directly in MySQL: INSERT INTO test_table (id, name, birthday) VALUES(1, 'chen', '2017-12-12 15:00:00'); is correct)
problem solved:
When I encountered this problem, my first instinct was the time zone problem, but I didn't know how to start, so I could only try one by one.
First, I looked at the time zone on the server side, date -R, the displayed time zone is correct;
Then I checked the time zone used by MySQL: SHOW VARIABLES LIKE '%time_zone%'
The query results are as follows:
system_time_zone CST
time_zone SYSTEM
It is the same as the system time zone.
It means that there is no problem with the configuration of the MySQL database itself, then it is the configuration problem of the program itself.
But I compared my project with the previous project configuration and found no difference.
I saw a blog post during the Baidu process: https://segmentfault.com/q/1010000010791397
I found that the same situation happened with him, I was also using the new version 6.0 driver, but my MySQL version was 5.5.52-MariaDB.
My original configuration was as follows:
driver=com.mysql.jdbc.Driver url=jdbc\:mysql\://192.168.164.129\:3306/test?useSSL\=false&useUnicode\=true&characterEncoding\=utf8&autoReconnect\=true
Then added &serverTimezone\=Hongkong after the path
Modified as follows:
driver=com.mysql.jdbc.Driver url=jdbc\:mysql\://192.168.164.129\:3306/test?useSSL\=false&useUnicode\=true&characterEncoding\=utf8&autoReconnect\=true&serverTimezone\=Hongkong
Re-test the code and find that the above bugs are resolved.
Other blog posts for reference: http://blog.csdn.net/qq631431929/article/details/51731834
Time zone brief introduction: http://blog.sina.com.cn/s/blog_a72ec20c0101jgxd.html