mysql通过now()获取的时间不对
先用now()获取系统时间,发现时间不对(差8个小时):
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-04-25 14:44:46 | +---------------------+
再查看linux系统及mysql的时区设置(system_time_zone是linux系统设置的时区,time_zone是mysql设置的时区):
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。mysql> show variables like "%time_zone%"; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | xxx | | time_zone | yyy | +------------------+--------+
================= 解决方案 ================================
1、首先要保证time_zone的值为SYSTEM:
vi /etc/my.cnf 在[mysqld]区域中加上: default-time_zone = 'SYSTEM'
2、然后要保证linux系统时间是正确的:

更多精彩