午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:101日期: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ù)庫(kù)時(shí)區(qū)問題

插入情況

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

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

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

再查詢此條記錄

關(guān)于SpringBoot mysql數(shù)據(jù)庫(kù)時(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ù)庫(kù)時(shí)區(qū)問題

修改配置后,需要重啟SpringBoot

新增情況

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

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

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

查詢記錄

關(guān)于SpringBoot mysql數(shù)據(jù)庫(kù)時(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ù)庫(kù)時(shí)區(qū)問題

SpringBoot查詢,一樣

關(guān)于SpringBoot mysql數(shù)據(jù)庫(kù)時(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ù)庫(kù)時(shí)區(qū)問題

關(guān)于SpringBoot mysql數(shù)據(jù)庫(kù)時(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ù)庫(kù)時(shí)區(qū)問題

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

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

重新把time_zone改回東3

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

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

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

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

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

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

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

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

SpringBoot查詢

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

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

關(guān)于SpringBoot mysql數(shù)據(jù)庫(kù)時(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變量,庫(kù)中數(shù)據(jù)直接變更。但是不影響當(dāng)前會(huì)話查詢,新增數(shù)據(jù),就會(huì)根據(jù)time_zone調(diào)整量,調(diào)整實(shí)際入庫(kù)。

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

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

插入

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

庫(kù)中

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

查詢

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

time_zone從東3修改為東5

重新打開庫(kù)

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

不啟動(dòng)SpringBoot

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

重啟SpringBoot,還是一樣。

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

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

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

查詢

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

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

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 色视频在线观看 | 色综合天天综合 | 免费成人黄色网址 | 在线资源站 | 亚洲第一黄色 | 国产精品成人免费 | 在线观看日本黄色 | 91青青操| 国产69久久 | 中文字幕高清视频 | 欧美精品一二三四区 | 国产一级免费视频 | 天天做天天爱天天爽综合网 | 在线中文字幕一区 | 亚洲黄色一级大片 | 91久久一区| 日本黄页免费 | 国产乱妇4p交换乱免费视频 | 女女综合网 | 欧美性妇| 三级国产在线 | 成人性视频在线播放 | 亚洲国产91 | av福利影院| 国产又粗又硬又长 | 久久永久视频 | 中文字幕第9页 | 久久国产一区 | 超碰伊人 | 91一区二区三区在线观看 | 美女三级黄色片 | 中文字幕在线视频一区 | 欧美综合一区二区三区 | 国精产品99永久一区一区 | 激情xxxx| 午夜影院视频 | 三级欧美韩日大片在线看 | 四虎影院最新网址 | 日韩av综合| 亚洲第一视频在线播放 | 亚洲午夜精品在线 |