1. 程式人生 > >mysql異常之: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

mysql異常之: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

連線資料庫時顯示:

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的時區即可:

重啟mysql, 再次輸入: show variables like '%time_zone%';

如果還是顯示time_zone    |     SYSTEM

可能是由於還沒有更新快取導致的, 再次輸入: set time_zone='+8:00';

set global time_zone = ‘+8:00‘; ##修改mysql全域性時區為北京時間,即我們所在的東8區
set time_zone = ‘+8:00‘; ##修改當前會話時區
flush privileges; #立即生效

  

 如果顯示Query Ok, 0 rows affected, 那麼很可能是已經更新時區成功了

如果以上方法還不可以解決問題, 那麼嘗試在程式碼中做調整

jdbc:mysql://127.0.0.1:3306/onestep?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8

重啟服務和應用即可