在使用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