首頁  >  文章  >  資料庫  >  一文搞定Mysql時區錯誤問題

一文搞定Mysql時區錯誤問題

WBOY
WBOY轉載
2022-08-25 11:40:112839瀏覽

推薦學習:mysql影片教學

#今天在做專案的時候遇到一個關於mysql時區的問題,在這裡總結記錄一下解決過程,希望可以幫助有需要的人。

問題描述

在做專案的時候突然遇到以下的報錯,可以看到是說 資料庫的時區錯誤,這裡使用的是Mysql 8.0.15資料庫。

這裡試用了idea提供的資料庫視覺化外掛。

以下報錯使得無法存取資料庫。

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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.
### 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 'Öйú±ê׼ʱ¼ä' 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.

原因分析

這裡首先考慮是資料庫本身的預設時區設定的問題,

其次考慮在設定idea資料庫視覺化外掛連線的時候的時區的設定問題

解決方案:

透過以下步驟解決了此問題:

開啟命令窗口,進入mysql服務:

接著查詢時區:

show variables like "%time_zone%";

這裡顯示SYSTEM表示跟隨系統,一般情況下是沒有問題的,但是偶爾也會出現問題,這裡我們就直接更改成' 8:00'

set global time_zone='+08:00';

注意:這只是暫時修改,重啟mysql服務後就會失效

下面介紹永久修改:
永久的修改:修改mysql的設定檔my.ini,新增:default-time-zone=' 08:00',重啟mysql生效,注意一定要在[mysqld] 之下加,否則會出現unknown variable 'default-time -zone= 8:00'

接下來再去idea裡面測試一下。

發現結果還是報錯,那麼據考慮是idea資料庫視覺化外掛程式的連結配置問題。

接下來修改idea資料庫視覺化外掛程式配置:

在這裡加上時區' 8:00',進行測試。完美解決。

推薦學習:mysql影片教學

#

以上是一文搞定Mysql時區錯誤問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:jb51.net。如有侵權,請聯絡admin@php.cn刪除