MySQL JDBC Driver 5.1.33 - Time Zone Issue

前端 未结 30 1190
栀梦
栀梦 2020-11-22 05:22

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

相关标签:
30条回答
  • 2020-11-22 06:01

    I solved putting below connection string in the URL

    jdbc:mysql://localhost:3306/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
    
    0 讨论(0)
  • 2020-11-22 06:03

    From mysql workbench run the following sql statements:

    1. SET @@global.time_zone = '+00:00';
    2. SET @@session.time_zone = '+00:00';

    with the following sql statements check if the values were set:

    SELECT @@global.time_zone, @@session.time_zone;

    0 讨论(0)
  • 2020-11-22 06:05

    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

    0 讨论(0)
  • 2020-11-22 06:06

    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

    0 讨论(0)
  • 2020-11-22 06:06

    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
    
    0 讨论(0)
  • 2020-11-22 06:06

    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

    0 讨论(0)
提交回复
热议问题