一文帶你永久擺脫Mysql時區(qū)錯誤問題(idea數(shù)據(jù)庫可視化插件配置)
項目場景:
今天在做項目的時候遇到一個關于mysql時區(qū)的問題,在這里匯總記錄一下解決過程,希望可以幫助到有需要的人。
問題描述
在做項目的時候突然遇到以下的報錯,可以看到是說 數(shù)據(jù)庫的時區(qū)錯誤,這里使用的是Mysql 8.0.15數(shù)據(jù)庫。
這里試用了idea提供的數(shù)據(jù)庫可視化插件。
以下報錯使得無法訪問數(shù)據(jù)庫。
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: The server time zone value '?D1ú±ê×?ê±??' 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 error may exist in StudentMapper.xml ### The error may involve ll.getAll ### The error occurred while executing a query ### Cause: java.sql.SQLException: The server time zone value '?D1ú±ê×?ê±??' 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.
原因分析
這里首先考慮是數(shù)據(jù)庫本身的默認時區(qū)設置的問題,
其次考慮在設置idea數(shù)據(jù)庫可視化插件連接的時候的時區(qū)的設置問題
解決方案:
通過以下步驟解決了此問題:
打開命令窗口,進入mysql服務:

接著查詢時區(qū):
show variables like "%time_zone%";

這里顯示SYSTEM表示跟隨系統(tǒng),一般情況下是沒有問題的,但是偶爾也會出現(xiàn)問題,這里我們就直接更改成'+8:00'
set global time_zone='+08:00';
注意:這只是臨時修改,重啟mysql服務后就會失效
下面介紹永久修改:
永久的修改:修改mysql的配置文件my.ini,添加:default-time-zone=’+08:00’,重啟mysql生效,注意一定要在 [mysqld] 之下加 ,否則會出現(xiàn) unknown variable ‘default-time-zone=+8:00’

接下來再去idea里面測試一下。
發(fā)現(xiàn)結果還是報錯,那么據(jù)考慮是idea數(shù)據(jù)庫可視化插件的鏈接配置問題。
接下來修改idea數(shù)據(jù)庫可視化插件配置:


在這里加上時區(qū)’+8:00’,進行測試。完美解決。
總結
問題不大,但也著實頭疼,一次性解決不很完美。
到此這篇關于帶你永久擺脫Mysql時區(qū)錯誤問題的文章就介紹到這了,更多相關Mysql時區(qū)錯誤問題內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
MySQL 5.6下table_open_cache參數(shù)優(yōu)化合理配置詳解
這篇文章主要介紹了MySQL 5.6下table_open_cache參數(shù)合理配置詳解,需要的朋友可以參考下2018-03-03

