JDBC driver連接MySQL運行報錯The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than


出錯原因:

因為安裝mysql的時候時區設置的不正確。 mysql默認的是美國的時區,而我們中國大陸要比他們遲8小時,采用GMT+8:00格式。

也就是說是數據庫和系統時區差異所造成的。

 

驗證:運行cmd登錄mysql,控制台輸入:

 

show variables like '%time_zone%';

如果顯示SYSTEM則是時區有問題,有兩個解決方法:

 

 

解決方法一:

在jdbc連接的url后面加上serverTimezone=GMT即可解決問題,如果需要使用gmt+8時區,需要寫成GMT%2B8。

1.1

按照網上的教程,我第一次是在數據庫后面加上(沒有引號):"?serverTimezone=GMT+8"

報錯:java.sql.SQLException: No timezone mapping entry for 'GMT 8' ; 

 

1.2

后來又查到,需要將+改成%2B,"?serverTimezone=GMT%2B8"就可以了:

 1.3 

 有大神提到:如果把數據庫時區改了,那么插入數據庫的時間都會自動減8小時。(暫時還沒有用到)

解決方案:比如是SpringBoot2.0,在jdbc配置上加了一個&serverTimezone=UTC就行了。

 

解決方法二:

修改MySQL的配置文件,MySQL配置文件是my.ini文件在你的安裝目錄下去找,我的是C:\web\mysql-8.0.13\my.ini

用記事本打開,在[mysqld]節點后面加上這句話:

default-time-zone='+08:00'

再次運行:

show variables like '%time_zone%';

 

顯示+8:00就成功了:

 此時不用在寫?serverTimezone=GMT%2B8都可以運行成功。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 DBEAVER連接MySQL運行報錯The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than 使用JDBC連接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 關於MySql升級JDBC架包導致時區問題報錯(The server time zone value '?й???????' is unrecognized or represents more than one time zone) 解決使用DBeaver連接MySQL時報錯-The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 報錯:Cannot create PoolableConnectionFactory (The server time zone value 'CST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverT mysql連接異常:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zo錯誤 JDBC連接數據庫報錯:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. ...... 解決JDBC連接MySQL 8時得異常:java.sql.SQLException: 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的解決方法 springboot報錯The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM