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

本文介绍了在使用Spring Boot操作MySQL数据库时遇到的时区配置问题,并提供了详细的解决方案,包括如何正确配置application.yml文件和调整连接字符串中的时区参数。

在使用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

这样就好了,多踩踩坑

转载于:https://www.cnblogs.com/zhikou/p/8644478.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值