1. 程式人生 > >Spring boot +mybatis 連接mysql數據庫,獲取JDBC失敗,服務器時區價值”Oйu±e×¼e±¼的識別或代表多個時區

Spring boot +mybatis 連接mysql數據庫,獲取JDBC失敗,服務器時區價值”Oйu±e×¼e±¼的識別或代表多個時區

driver 配置文件 rep har mysql數據庫 val 獲取 cau ann

報出的錯誤

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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.

錯誤原因為jdbc配置文件

錯誤文件

spring.datasource.url=jdbc:mysql://localhost:3306/book
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

解決:在url連接後加上

?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
正確:
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

Spring boot +mybatis 連接mysql數據庫,獲取JDBC失敗,服務器時區價值”Oйu±e×¼e±¼的識別或代表多個時區