SpringBoot 2.0,连接mysql出错:Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException

目录

完整报错:

解决方案:


完整报错:

2019-10-04 09:39:16.195 ERROR 5816 --- [eate-1687875270] com.alibaba.druid.pool.DruidDataSource   : create connection SQLException, url: jdbc:mysql:///XXX errorCode 0, state 01S00

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:129) ~[mysql-connector-java-8.0.17.jar:8.0.17]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.17.jar:8.0.17]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.17.jar:8.0.17]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.17.jar:8.0.17]

Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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


解决方案:

根据提示,判断是时区问题,需要对时区进行配置。

在数据库配置文件中URL这一行后面加上:?serverTimezone=UTC

spring.datasource.url=jdbc:mysql:///myDBname?serverTimezone=UTC

如果存在中文乱码,可以加上:?useUnicode=true&characterEncoding=UTF-8  可以组合使用,写法如下:

spring.datasource.url=jdbc:mysql:///myDBname?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

 

你可能感兴趣的:(Java)