连接mysql数据库报错java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.

在使用spring boot操作数据库的时候,莫名其妙抛了一个错误:mysql6.0.6时间区域时差问题

 ava.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.  
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)  
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)  
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)  
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)  
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:489)  
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:69)  
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1606)  
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)  
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)  
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)  
    at java.sql.DriverManager.getConnection(Unknown Source)  
    at java.sql.DriverManager.getConnection(Unknown Source)  
    at com.java1234.util.DbUtil.getCon(DbUtil.java:12)  
    at com.java1234.realm.MyRealm.doGetAuthenticationInfo(MyRealm.java:55)  
    at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:571)  
    at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)  

 

我的yml配置文件

server:
  port: 8088
spring:
  profiles:
    active: dev
  datasource:
    password: 123456
    url: jdbc:mysql://localhost:3306/person
    username: root
    driver-class-name: com.mysql.jdbc.Driver

    # 使用druid数据源
#mybatis:
#  type-aliases-package: com.zakyoung.springboot.vue.entities

我的pom.xml的配置文件

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.6</version>
        </dependency>

我是用的6.0.6版本的

修改配置文件加上

serverTimezone=UTC”不然会因为时区问题报错,这里用了CTT中国台湾时区避免产生8小时时差

 url: jdbc:mysql://localhost:3306/person?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

这样就好了,多踩踩坑

posted @ 2018-03-25 15:06  appleYang  阅读(15141)  评论(1编辑  收藏  举报