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


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

    1. // 查看时间
    2. [root@localhost ~]# date
    3. 2022年 08月 03日 星期三 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. 2022年 08月 04日 星期四 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

  • 相关阅读:
    基于Nodejs的电博客管理系统的设计和实现
    中级C++:哈希
    《要么孤独 要么庸俗》 笔记
    (四)Shell编程之算数运算
    云原生技术-微服务SpringCloud(1)
    一键部署监控
    Minecraft 1.12.2 彩色渐变字体 模组发布
    Hive 任务限制同时运行的任务数量的配置
    《Care Bears 爱心熊》人物化身来到 The Sandbox 元宇宙!
    Spring AOP 分享
  • 原文地址:https://blog.csdn.net/weixin_42280959/article/details/126155494