当前位置:网站首页>MySQL時間、時區、自動填充0的問題
MySQL時間、時區、自動填充0的問題
2022-07-06 12:16:00 【阿杆.】
數據庫時間更新問題 2022/4/13
在數據庫更新用戶信息的時候,每次都會更新注册時間,這一波我屬實是懵逼了。
起初以為是mybatis順帶把注册時間給更新了,然後排查了一下代碼,沒發現問題,打開mybatis日志一看,sql語句也都正確,完全沒有看到更新注册時間的代碼。
轉念一想,沒准是數據庫的問題。發現注册時間這個字段勾選了根據當前時間戳更新的選項,突然懂了,原來這個選項是每次更新內容都會把這個字段給更新了。取消之後再測代碼,一切正常。

數據庫時區錯誤問題 2022/4/20
今天調試了一下某個接口,涉及到時間的,我是從Java裏面獲取當前時間然後轉到數據庫裏的(其實我覺得用數據庫裏的 now 也可以),然後就出問題了,存進去的時間比實際時間要慢幾個小時。
我仔細一想,不會是 new Timestamp(System.currentTimeMillis()); 這句代碼獲取的時間又問題吧,果斷測試了一下,發現並不是它的問題,那就肯定是數據庫的問題了,但是我看數據庫自動更新時間戳的那個時間又是對的。想了一下,可能是轉過去的時候,時區的問題。
之前寫yaml配置文件的時候,一直跟著老師寫的,老師也是這麼寫的 jdbc:mysql://127.0.0.1:3306/blog?serverTimezone=UTC ,結果我一百度,好家夥,這個時區是世界統一時間,比北京時間慢8小時,改成 serverTimezone=Asia/Shanghai 就解决了。
數據庫填充0 2022/4/20
在mysql5.6中,int等數字類型可以選擇 填充0 。

填充0的意思不是說默認值為0,而是指 在顯示的時候,默認向左側填充0,即 20 會顯示成 0000000020 ,當然左側的0不一定跟我寫的一樣多,這裏我只是打個比方。
如果不想要自動填充這麼多比特0,直接取消
填充零這個選項就可以了。
边栏推荐
- Reno7 60W super flash charging architecture
- Redis based distributed locks and ultra detailed improvement ideas
- Types de variables JS et transformations de type communes
- Analysis of charging architecture of glory magic 3pro
- [golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
- Basic knowledge of lithium battery
- level16
- C language callback function [C language]
- Detailed explanation of Union [C language]
- 锂电池基础知识
猜你喜欢

History object

基于Redis的分布式ID生成器

RT-Thread API参考手册

Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer

js 变量作用域和函数的学习笔记

Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍

Vscode basic configuration

Basic operations of databases and tables ----- creating data tables

Unit test - unittest framework
![[Red Treasure Book Notes simplified version] Chapter 12 BOM](/img/ff/0ad410b5b556c0e16a4076a2a0577b.jpg)
[Red Treasure Book Notes simplified version] Chapter 12 BOM
随机推荐
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
Redis based distributed ID generator
【ESP32学习-1】Arduino ESP32开发环境搭建
GCC compilation options
Characteristics, task status and startup of UCOS III
Oppo vooc fast charging circuit and protocol
ES6语法总结--下篇(进阶篇 ES6~ES11)
Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
IOT system framework learning
JS变量类型以及常用类型转换
STM32 如何定位导致发生 hard fault 的代码段
Understanding of AMBA, AHB, APB and Axi
imgcat使用心得
RT-Thread API参考手册
Imgcat usage experience
open-mmlab labelImg mmdetection
Unit test - unittest framework
Arduino JSON data information parsing
E-commerce data analysis -- User Behavior Analysis
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree