MySql:java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents。

QUESTION:

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.

 

ANSWER:

一:原因

博主在剛開始學習SpringBoot的時候,整合mybatis框架使用MySql數據庫配置時出現以上問題,經過查閱資料,找到解決方案,

原因是因爲使用了Mysql Connector/J 6.x以上的版本,然後就報了時區的錯誤

遇到的問題 servertime=UTC導致時間差8個小時

二:解決方法

在配置mysql的URL加上時區:

serverTimezone=UTC
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC

雖然上面加上時區程序不出錯了,但是我們在用java代碼插入到數據庫時間的時候卻出現了問題。

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

UTC + (+0800) = 本地(北京)時間。

將時區改成中國標準時間:

serverTimezone=Asia/Shanghai

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章