国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

關于SpringBoot mysql數據庫時區問題

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

后端開發中常見的幾個時區設置

第一個設置點配置文件 spring.jackson.time-zone

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

第三個設置點 mysql time_zone變量

詞義

serverTimezone臨時指定mysql服務器的時區

spring.jackson.time-zone 設置spring默認時區

system_time_zone mysql服務器時區 ,time_zone默認System追隨system_time_zone

幾種情況

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

關于SpringBoot mysql數據庫時區問題

插入情況

關于SpringBoot mysql數據庫時區問題

關于SpringBoot mysql數據庫時區問題

關于SpringBoot mysql數據庫時區問題

再查詢此條記錄

關于SpringBoot mysql數據庫時區問題

個人覺得Spring默認時區為格林尼治時區,web服務器當前時區為東八區,進行加8操作。

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

createTime 為 timestamp類型

關于SpringBoot mysql數據庫時區問題

修改配置后,需要重啟SpringBoot

新增情況

關于SpringBoot mysql數據庫時區問題

數據庫中顯示

關于SpringBoot mysql數據庫時區問題

查詢記錄

關于SpringBoot mysql數據庫時區問題

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

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

改變后,上條記錄往后調整2小時。

關于SpringBoot mysql數據庫時區問題

SpringBoot查詢,一樣

關于SpringBoot mysql數據庫時區問題

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

當time_zone變化時,回話沒結束,serverTimeZone東8還是對應time_zone的東3

SpringBoot插入

關于SpringBoot mysql數據庫時區問題

關于SpringBoot mysql數據庫時區問題

個人理解,serverTimeZone東8 還是和 time_zone 東3對應,但是插入發現 當前time_zone已經改成東5,就加2小時。

重啟SpringBoot,重新查詢

關于SpringBoot mysql數據庫時區問題

關于SpringBoot mysql數據庫時區問題

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

重新把time_zone改回東3

關于SpringBoot mysql數據庫時區問題

改回重新打開表,發現又回來了

不啟動SpringBoot,查詢數據,還是老樣子

關于SpringBoot mysql數據庫時區問題

此時,添加一條數據。

關于SpringBoot mysql數據庫時區問題

往前推了2小時。

關于SpringBoot mysql數據庫時區問題

SpringBoot查詢

關于SpringBoot mysql數據庫時區問題

重啟SpringBoot,查出來就是庫中數據。

關于SpringBoot mysql數據庫時區問題

總結:

1、timeStamp類型存儲時間數據,當time_zone和serverTimeZone不統一情況,會話中,表中時間數據,按照serverTimeZone設定

2、如果過程中,修改了time_zone變量,庫中數據直接變更。但是不影響當前會話查詢,新增數據,就會根據time_zone調整量,調整實際入庫。

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

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

插入

關于SpringBoot mysql數據庫時區問題

庫中

關于SpringBoot mysql數據庫時區問題

查詢

關于SpringBoot mysql數據庫時區問題

time_zone從東3修改為東5

重新打開庫

關于SpringBoot mysql數據庫時區問題

不啟動SpringBoot

關于SpringBoot mysql數據庫時區問題

重啟SpringBoot,還是一樣。

修改serverTimeZone為GMT,其他不改動

關于SpringBoot mysql數據庫時區問題

關于SpringBoot mysql數據庫時區問題

查詢

關于SpringBoot mysql數據庫時區問題

總結:如果是datetime類型,serverTimeZone說了算。

以上就是關于SpringBoot mysql數據庫時區問題的詳細內容,更多關于SpringBoot mysql時區的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
主站蜘蛛池模板: 隆子县| 吕梁市| 揭西县| 武鸣县| 房山区| 津市市| 成都市| 江达县| 梅州市| 湖南省| 德钦县| 县级市| 巴中市| 永年县| 新民市| 永川市| 湖州市| 宁明县| 鸡东县| 揭阳市| 黄龙县| 西乡县| 阿克苏市| 襄樊市| 嫩江县| 阿鲁科尔沁旗| 博客| 洛川县| 罗甸县| 濮阳市| 巴塘县| 沛县| 定州市| 宜黄县| 静宁县| 西昌市| 谢通门县| 叶城县| 黄大仙区| 抚松县| 曲阳县|