spring boot連接mysql提示The server time zone value xxx錯(cuò)誤

在使用spring boot +Mysql組合的時(shí)候。遇到了連接數(shù)據(jù)庫(kù)錯(cuò)誤。信息:The server time zone value xxx

Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

?

查看錯(cuò)誤的數(shù)據(jù)庫(kù)鏈接:

jdbc:mysql://127.0.0.1:3306/springbootautocode?user=root&password=123456

?

錯(cuò)誤原因分析:

這是因?yàn)閙ysql 服務(wù)器時(shí)區(qū)問(wèn)題導(dǎo)致的。

解決方案一:

直接在url后面添加:&serverTimezone=UTC

如果想或者添加:serverTimezone=GMT%2B8

因?yàn)橹袊?guó)的時(shí)區(qū)是在東八區(qū)。所以這里設(shè)置時(shí)區(qū)

解決方案二:

修改mysql 服務(wù)器的時(shí)區(qū)配置。

查看當(dāng)前mysql服務(wù)器時(shí)區(qū)語(yǔ)句:

show variables like '%time_zone%';

?

修改time_zone的值為+8:00語(yǔ)句:

set global time_zone='+8:00';

修改后:

?

這里不推薦第二種修改方式。

因?yàn)槿绻薷牧朔?wù)器時(shí)區(qū)的話,原來(lái)老數(shù)據(jù)的時(shí)間就不比時(shí)間少8個(gè)小時(shí)。這個(gè)時(shí)候會(huì)導(dǎo)致很多未知的問(wèn)題出現(xiàn)。

所以強(qiáng)烈推薦第一種修改方式。方便又簡(jiǎn)單。

下面看看凱哥的:

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springbootautocode?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8

修改完成后,重啟服務(wù),就可以正常訪問(wèn)了。

本文來(lái)源于凱哥個(gè)人博客,原文地址:http://www.kaigejava.com/article/detail/438

凱哥個(gè)人博客:www.kaigejava.com

凱哥個(gè)人公眾號(hào):凱哥Java

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容