• mysql 默认时间写入时差问题


    1)设置linux系统时间,这以centos为例

    1. // 查看时间
    2. [root@localhost ~]# date
    3. 20220803日 星期三 19:34:21 CST
    4. // 同步网络时间
    5. [root@localhost ~]# yum -y install ntp ntpdate
    6. 已加载插件:fastestmirror
    7. Loading mirror speeds from cached hostfile
    8. epel/x86_64/metalink | 6.6 kB 00:00:00
    9. * base: mirrors.ustc.edu.cn
    10. * epel: mirrors.bfsu.edu.cn
    11. * extras: mirrors.njupt.edu.cn
    12. * updates: mirrors.njupt.edu.cn
    13. base | 3.6 kB 00:00:00
    14. docker-ce-stable | 3.5 kB 00:00:00
    15. epel | 4.7 kB 00:00:00
    16. extras | 2.9 kB 00:00:00
    17. updates | 2.9 kB 00:00:00
    18. (1/2): epel/x86_64/updateinfo | 1.1 MB 00:00:05
    19. (2/2): epel/x86_64/primary_db | 7.0 MB 00:00:17
    20. 软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
    21. 软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
    22. 无须任何处理
    23. [root@localhost ~]# ntpdate cn.pool.ntp.org
    24. 4 Aug 10:43:19 ntpdate[2007]: step time server 139.199.215.251 offset 54409.400114 sec
    25. [root@localhost ~]# hwclock --systohc
    26. // 查看时间
    27. [root@localhost ~]# date
    28. 20220804日 星期四 10:43:42 CST
    29. // 查看时差
    30. [root@localhost ~]# timedatectl
    31. Local time: 四 2022-08-04 10:45:31 CST
    32. Universal time: 四 2022-08-04 02:45:31 UTC
    33. RTC time: 四 2022-08-04 02:45:25
    34. Time zone: Asia/Shanghai (CST, +0800)
    35. NTP enabled: yes
    36. NTP synchronized: no
    37. RTC in local TZ: no
    38. DST active: n/a
    39. // 如果时差有问题 设置时差
    40. [root@localhost ~]# timedatectl set-timezone Asia/Shanghai

    2)如果是容器部署mysql  设置容器时间

    1. // 进入容器
    2. [root@localhost ~]# docker exec -it mysql bash
    3. // 移除时间文件
    4. root@b7238f2a5cef:/# rm /etc/localtime
    5. // 挂载系统时间文件到容器
    6. root@b7238f2a5cef:/# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    7. root@b7238f2a5cef:/# exit
    8. exit
    9. // 重启容器
    10. [root@localhost ~]# docker restart mysql
    11. mysql
    12. // 查看时间
    13. [root@localhost ~]# docker exec -it mysql bash
    14. root@b7238f2a5cef:/# date
    15. Thu Aug 4 10:50:29 CST 2022

  • 相关阅读:
    MySQL8.0优化 - 事务的状态
    新手树莓派4B安装Supervised+Home Assistant
    【人工智能】xAI——“X宇宙”又增添了一位新成员
    Hexagon cDSP芯片简介
    开源一款基于EG1151的大功率同步整流可调升降压电源模块(支持TypeC PD快充输入)
    0077__浅析C++临时对象的产生相关问题
    Delta Lake: High-Performance ACID Table Storage over Cloud Object Stores
    以交易为生是一种什么体验?
    使用国内源加速pip安装包
    facebook审核流程
  • 原文地址:https://blog.csdn.net/weixin_42280959/article/details/126155494