zoukankan      html  css  js  c++  java
  • mysql5.7写入数据时间相差13/14小时解决

    原因

    mysql5.7默认时区使用SYSTEM,如果服务器时间为中国区(+08:00),那么mysql的system_time_zone变量为CST

    而CST可能有以下四种解释,在不通项目中可能出现不一致

    美国中部时间 Central Standard Time (USA) UTC-05:00 / UTC-06:00
    澳大利亚中部时间 Central Standard Time (Australia) UTC+09:30
    中国标准时 China Standard Time UTC+08:00
    古巴标准时 Cuba Standard Time UTC-04:00

    在JAVA中CST为美国中部时间,夏令时为UTC-05:00,其他时间为UTC-06:00,与中国区相差13/14个小时;

    在创建数据库连接时会自动从数据库获取包括时区在内的配置信息,导致时区配置错误。

    解决

    1. 在连接字符串中指定时区

    jdbc:mysql://xxxx:3306/schema?serverTimezone=Asia/Shanghai

    1. 修改mysql配置,设置指定默认时区
    default-time-zone=Asia/Shanghai
    
    • 另:mysql默认日志时区为UTC,可通过以下配置改为系统时区
    log-timestamps=system
    
  • 相关阅读:
    14-Reverse Integer
    13.Merge k Sorted Lists
    12-Add Digits
    11-String to Integer (atoi)
    10.Power of Two-Leetcode
    9. Delete Node in a Linked List
    使用Openmp并行化
    C++编译过程与内存空间
    C++栈溢出
    程序(进程)内存空间分布深入理解
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294628.html
Copyright © 2011-2022 走看看