mysql通过now()获取的时间不对
先用now()获取系统时间,发现时间不对(差8个小时):
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-04-25 14:44:46 | +---------------------+
再查看linux系统及mysql的时区设置(system_time_zone是linux系统设置的时区,time_zone是mysql设置的时区):
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系统时间是正确的: