SpringBoot數據庫配置報錯

SpringBoot數據庫配置報錯

SpringBoot在連接數據庫的時候會出現如下報錯,原因是時間區域時差問題

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.

這時候需要在配置數據庫的url後面加上

serverTimezone=GMT%2B8 

UTC代表的是全球標準時間 ,但是我們使用的時間是北京時區也就是東八區,領先UTC八個小時

# 連接四大參數
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8 
spring.datasource.username=root
spring.datasource.password=root
# 可省略,SpringBoot自動推斷
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章