Spring boot project integration myba error java.sql.SQLException: The server time zone value' й ׼ʱ ' is unrecognized

The spring boot project reports an error java.sql.SQLException: The server time zone value' й ׼ʱ ' is unrecognized, the original translation and explanation is that the time zone is incorrect

The root cause of the error is that the mysql-connection-java version is too high, which leads to time zone problems.
Insert picture description here
Error code:

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]
	。。。。。

Solution 1

Add the lower version number of mysql-connector-java such as: 5.1.47. If you add the version number 6.0.6, it won't work. It may be because the version is too high.

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

Solution 2

Do not add the version number or the version number is 6 or above, the solution: add the following to the configuration file of the connection database, time zone Asia/Shanghai
Method 1:

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

Insert picture description here
Way two:

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

Insert picture description here

Solution 3 (not verified yet)

Insert picture description here
Reprint address: https://blog.csdn.net/qq_43371004/article/details/98385445

Guess you like

Origin blog.csdn.net/rao991207823/article/details/105399160