今天給自己項目打包到服務器發布時,運行時,發現報
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.
錯誤
經過查詢資料發現是
MySql本身的時區設置的問題導致的
解決辦法:
方法一:
1.在mysql安裝位置下找到my.ini
文件;
2.修改my.ini
文件中:在[mysqld]
下方,添加
default-time-zone='+08:00'
3.重啟即可
方法二:
我是springboot項目,使用tomcat發布時報的,可以使用一下方法解決
在你項目的數據庫配置url位置,后面加上 serverTimezone=UTC
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
如果發現新加數據比當前時間少8個小時,或者查詢顯示出來的數據比數據庫入庫的時間多8個小時,可以改為:serverTimezone=GMT%2B8
這樣新添加的數據為正常時間
結束