You must configure either the server or JDBC driver (via the serverTimezone configuration property)

某次連接Mysql數據庫時候出現了報錯

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. 在這裏插入圖片描述

直接谷歌翻譯,大概意思就是和服務器時區不一致,需要調整
MySql安裝默認設置爲美國時區,而北京時間比美國遲8小時。解決方法也很簡單

解決方法

在db連接串後面加上:?serverTimezone=UTC,完整示例:jdbc:mysql://localhost:3306/dbname?serverTimezone=UTC【可以指定時區問題】

補充

在db連接串後面加上:?useUnicode=true&characterEncoding=UTF-8,完整示例:jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8 【可以解決中文亂碼問題】
當然也可以聯合起來用jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

網上還有一種辦法就是修改mysql安裝路徑下的my.ini文件
在[mysqld]下方添加:default-time-zone=’+08:00’。(注意引號)

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