問(wèn)題描述
springboot中連接mysql漂彤,啟動(dòng)時(shí)報(bào)錯(cuò)悬襟,錯(cuò)誤如下:
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.
問(wèn)題原因
Springboot2.1.0及以上钉凌,在沒(méi)有指定MySQL驅(qū)動(dòng)版本的情況下损同,自動(dòng)依賴的驅(qū)動(dòng)是8.0.13很高的版本遏考,這是由于數(shù)據(jù)庫(kù)和系統(tǒng)時(shí)區(qū)差異造成的慈鸠。低版本的MySQL JDBC驅(qū)動(dòng)(5.1.28)不會(huì)存在時(shí)區(qū)問(wèn)題
解決辦法
- 方法1:在數(shù)據(jù)庫(kù)中修改數(shù)據(jù)庫(kù)時(shí)區(qū)
set global time_zone = '+8:00'; ##修改mysql全局時(shí)區(qū)為北京時(shí)間,即我們所在的東8區(qū)
set time_zone = '+8:00'; ##修改當(dāng)前會(huì)話時(shí)區(qū)
flush privileges; #立即生效
-
方法2:在數(shù)據(jù)庫(kù)配置文件中指定時(shí)區(qū)(my.ini中)