spring boot 项目整合myba报错 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized

spring boot 项目报错 java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized,翻译解说原文是时区不对

报错根源在于mysql-connection-java版本太高导致时区问题。
spring boot 项目整合myba报错 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized_第1张图片
报错代码:

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.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	。。。。。

解决方式1

加上 mysql-connector-java 较低的版本号如:5.1.47,如果加上版本号6.0.6也不行,可能是因为版本太高。

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

解决方式2

不加版本号或者版本号为6以上,解决方式:在连接数据库的配置文件中加上以下,时区亚洲/上海
方式一:

jdbc:mysql://127.0.0.1:3306/maven?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

在这里插入图片描述
方式二:

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

在这里插入图片描述

解决方式3(暂未验证)

spring boot 项目整合myba报错 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized_第2张图片
转载地址:https://blog.csdn.net/qq_43371004/article/details/98385445

你可能感兴趣的:(SpringBoot)