久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術(shù)文章
文章詳情頁

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

瀏覽:51日期:2023-03-06 08:36:12
尋找原因

后端開發(fā)中常見的幾個時區(qū)設(shè)置

第一個設(shè)置點配置文件 spring.jackson.time-zone

第二個設(shè)置點 高版本SpringBoot版本 mysql-connector-java 用的是8.X,mysql8.X的jdbc升級了,增加了時區(qū)(serverTimezone)屬性,并且不允許為空。

第三個設(shè)置點 mysql time_zone變量

詞義

serverTimezone臨時指定mysql服務(wù)器的時區(qū)

spring.jackson.time-zone 設(shè)置spring默認時區(qū)

system_time_zone mysql服務(wù)器時區(qū) ,time_zone默認System追隨system_time_zone

幾種情況

1、time_zone 為 System,serverTimezone為GMT+8,jackson.time-zone未定義

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

插入情況

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

再查詢此條記錄

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

個人覺得Spring默認時區(qū)為格林尼治時區(qū),web服務(wù)器當(dāng)前時區(qū)為東八區(qū),進行加8操作。

2、set GLOBAL time_zone = ’+3:00’,serverTimezone為GMT+8,jackson.time-zone為GMT+8

createTime 為 timestamp類型

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

修改配置后,需要重啟SpringBoot

新增情況

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

數(shù)據(jù)庫中顯示

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

查詢記錄

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

個人理解,serverTimezone設(shè)置覆蓋掉了mysql的time_zone變量,跟SpringBoot回話時區(qū)還是東8

3、上述環(huán)境,不重啟SpringBoot,直接改變time_zone = ’+5:00’

改變后,上條記錄往后調(diào)整2小時。

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

SpringBoot查詢,一樣

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

說明,timeStamp類型存儲的是格林尼治時間,加上time_zone時區(qū)

當(dāng)time_zone變化時,回話沒結(jié)束,serverTimeZone東8還是對應(yīng)time_zone的東3

SpringBoot插入

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

個人理解,serverTimeZone東8 還是和 time_zone 東3對應(yīng),但是插入發(fā)現(xiàn) 當(dāng)前time_zone已經(jīng)改成東5,就加2小時。

重啟SpringBoot,重新查詢

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

雖然,mysql變量time_zone為+5,但是重啟后,serverTimeZone直接覆蓋,設(shè)置時間區(qū)間為東8

重新把time_zone改回東3

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

改回重新打開表,發(fā)現(xiàn)又回來了

不啟動SpringBoot,查詢數(shù)據(jù),還是老樣子

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

此時,添加一條數(shù)據(jù)。

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

往前推了2小時。

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

SpringBoot查詢

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

重啟SpringBoot,查出來就是庫中數(shù)據(jù)。

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

總結(jié):

1、timeStamp類型存儲時間數(shù)據(jù),當(dāng)time_zone和serverTimeZone不統(tǒng)一情況,會話中,表中時間數(shù)據(jù),按照serverTimeZone設(shè)定

2、如果過程中,修改了time_zone變量,庫中數(shù)據(jù)直接變更。但是不影響當(dāng)前會話查詢,新增數(shù)據(jù),就會根據(jù)time_zone調(diào)整量,調(diào)整實際入庫。

3、SpringBoot重啟,其實就是新會話。情況同上。

4、時間字段類型為datetime,serverTimezone為GMT+8,jackson.time-zone為GMT+8,time_zone為東3

插入

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

庫中

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

查詢

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

time_zone從東3修改為東5

重新打開庫

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

不啟動SpringBoot

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

重啟SpringBoot,還是一樣。

修改serverTimeZone為GMT,其他不改動

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

查詢

關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題

總結(jié):如果是datetime類型,serverTimeZone說了算。

以上就是關(guān)于SpringBoot mysql數(shù)據(jù)庫時區(qū)問題的詳細內(nèi)容,更多關(guān)于SpringBoot mysql時區(qū)的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 国产精品成人在线观看 | 狠狠av| 日本a在线| 亚洲欧美日韩另类一区二区 | 国产高清视频在线观看 | 日本一本视频 | 一区二区三区四区日韩 | 国产一区二区综合 | 欧美一级片在线观看 | 国产资源视频在线观看 | 一级欧美片| av大片| 久久99国产精品久久99大师 | 三级网站视频 | 精品中文字幕在线 | 亚洲精品一区二三区不卡 | 精品久久久久久久久久久久久久 | 韩国精品一区 | 国产免费黄色 | 日韩免费 | 欧美极品视频 | av网站免费看 | 国产福利一区二区三区四区 | а√天堂中文在线资源8 | 日韩不卡av | 在线观看一区二区三区四区 | 久久国产精品久久久久久 | 欧美在线a | 成人精品在线视频 | 欧美成人手机在线 | 不卡视频一区 | 国产69久久 | 美女视频久久 | 免费观看一级特黄欧美大片 | 免费黄色毛片视频 | 亚洲精品国产第一综合99久久 | 久草视频在线播放 | 欧美2区 | 午夜精品久久久久 | 伊人草| 久久久久久电影 |