I got a very strange problem.
My local timezone is UTC+8
. I think server's timezone is also UTC+8
according to the following command:
mysql> SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
+--------------------------------+
| TIMEDIFF(NOW(), UTC_TIMESTAMP) |
+--------------------------------+
| 08:00:00 |
+--------------------------------+
1 row in set (0.01 sec)
But Java's driver detect the server's timezone is UTC-5
. More specifically, assuming that my local time is 13:00
, if I insert a new Date()
into the database, then the actual time I inserted is 00:00
.
However, if I append serverTimezone=Asia/Shanghai
(which is UTF+8) to mysql's url, everything goes well.
Detail server's informations list below:
Ubuntu 14.04.5 LTS
Contents in
/etc/timezone
isAsia/Shanghai
Mysql Server version: 5.6.31-0ubuntu0.14.04.2-log (Ubuntu)
spring.datasource.driver-class-name
=com.mysql.cj.jdbc.Driver
Driver version:
mysql:mysql-connector-java:6.0.5
I've confused with this problem for long time, could anyone give me an answer?