mysql错误:java.sql.SQLException: The server time zone value ‘xxx‘ is unrecognized or represents 解决方法

错误内容:

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 specific 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.22.jar:8.0.22]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.22.jar:8.0.22]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.22.jar:8.0.22]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.22.jar:8.0.22]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.22.jar:8.0.22]
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) ~[mysql-connector-java-8.0.22.jar:8.0.22]

导致原因:

1,mysql驱动版本不对,使用的老版5.x mysql.引用的是mysql8.x驱动。

2,使用的8.x版本mysql.仍然使用的5.x的url连接字符串

解决(URL:添加serverTimezone=Asia/Shanghai):

#如果是mysql-connector-java-8.0.22驱动则使用下面的(理论6.0以上)
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/itqs?allowMultiQueries=true&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

猜你喜欢

转载自blog.csdn.net/wh445306/article/details/112119518