av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

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

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

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

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

第三個(gè)設(shè)置點(diǎn) mysql time_zone變量

詞義

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

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

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

幾種情況

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

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

插入情況

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

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

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

再查詢此條記錄

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

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

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

createTime 為 timestamp類型

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

修改配置后,需要重啟SpringBoot

新增情況

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

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

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

查詢記錄

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

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

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

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

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

SpringBoot查詢,一樣

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

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

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

SpringBoot插入

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

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

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

重啟SpringBoot,重新查詢

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

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

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

重新把time_zone改回東3

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

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

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

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

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

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

往前推了2小時(shí)。

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

SpringBoot查詢

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

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

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

總結(jié):

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

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

3、SpringBoot重啟,其實(shí)就是新會(huì)話。情況同上。

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

插入

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

庫中

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

查詢

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

time_zone從東3修改為東5

重新打開庫

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

不啟動(dòng)SpringBoot

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

重啟SpringBoot,還是一樣。

修改serverTimeZone為GMT,其他不改動(dòng)

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

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

查詢

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

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

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 丝袜美腿一区二区三区 | 国产一区二区三区www | 久久99精品久久久久久国产越南 | 午夜国产 | 国产精品久久久久久中文字 | 一级黄色录像毛片 | 久久精品网| 美女在线视频一区二区三区 | 久久久高清| 久久久久久久一区二区三区 | 一级一片在线观看 | 久在线| 亚洲精品91| 日韩视频在线免费观看 | 亚洲午夜精品久久久久久app | 欧美精品片 | 精品久久电影 | 欧美日本韩国一区二区 | 亚洲成人观看 | 久久精品视频播放 | 国产精品欧美一区喷水 | 性网站免费 | 午夜精品久久久久久不卡欧美一级 | 欧美激情精品久久久久久 | 美女拍拍拍网站 | 久久久久亚洲视频 | 日韩欧美大片在线观看 | 欧美一级网站 | 亚洲精品视频免费观看 | 欧美三级在线 | 国产一在线观看 | 日韩a视频 | 日韩一区二区在线播放 | 国产精品不卡一区 | 999精品在线 | 精品日韩一区二区三区 | 一区二区三区免费 | 国产激情片在线观看 | 欧洲精品一区 | 中文字幕亚洲一区二区va在线 | 日韩视频在线免费观看 |