Some background:
I have a Java 1.6 webapp running on Tomcat 7. The database is MySQL 5.5. Previously, I was using Mysql JDBC driver 5.1.23 to connect to the DB. Ever
I solved putting below connection string in the URL
jdbc:mysql://localhost:3306/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
From mysql workbench run the following sql statements:
with the following sql statements check if the values were set:
SELECT @@global.time_zone, @@session.time_zone;
This worked for me.
on DBeaver 6.0 : Go to Connection Settings > Driver Properties > Server Time Zone > Set UTC.
Also, in spring boot config, had to set below property.
jdbc:mysql://localhost:/?serverTimezone=UTC
I executed following on my database side.
mysql> SET @@global.time_zone = '+00:00';
mysql> SET @@session.time_zone = '+00:00';
mysql> SELECT @@global.time_zone, @@session.time_zone;
I am using Server version: 8.0.17 - MySQL Community Server - GPL
source: https://community.oracle.com/thread/4144569?start=0&tstart=0
You can use the MySQL connector in the Maven dependency,
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.14</version>
</dependency>
Then you need the set the right parameters in the application.properties
file,
spring.datasource.url=jdbc:mysql://localhost:3306/UserReward?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=testuser
spring.datasource.password=testpassword
# MySQL driver
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
I had the same problem when I try to work with spring boot project on windows.
Datasource url should be:
spring.datasource.url=jdbc:mysql://localhost/database?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC