1. 程式人生 > 實用技巧 >連線MySQL異常:The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time

連線MySQL異常:The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time

轉自:https://blog.csdn.net/qq_40891588/article/details/85052923

連線MySQL異常: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.

連線資料庫時,出現時區異常:

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.

兩種解決方法:

  • 在資料庫連線語句後新增?serverTimezone=UTC,即預設0時區,但是要注意,該語句需要跟在資料庫連線語句的第一個位置,否則會報錯,例如:
jdbc.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&user&password&useUnicode=true&characterEncoding=utf-8
注意:這種方法會存在一個問題,在向資料庫插入時間欄位時,時間會比當前時間早8小時,即當前系統時間減8小時。

  • 修改Mysql的時區為東8區,執行如下命令即可:
set global time_zone='+8:00'