MySQL5.7慢查询日志时间与系统时间差8小时原因详解
在对慢查询进行查看的时候发现时间不对,正好与系统时间相差8个小时。
1、慢查询显示时间如下
# time: 2020-01-10t06:42:24.940811z
2、系统时间
$ date fri jan 10 14:42:31 cst 2020
3、查看数据库参数
mysql> show variables like 'log_timestamps'; +----------------+-------+ | variable_name | value | +----------------+-------+ | log_timestamps | utc | +----------------+-------+ 1 row in set (0.00 sec)
utc大家都知道是世界统一时间,而我现在的系统时间是东八区,比utc早了8个小时,这就对上了。查看官方文档看一下官网的解释。
log_timestamps
property value
command-line format --log-timestamps=#
introduced 5.7.2
system variable log_timestamps
scope global
dynamic yes
type enumeration
default value utc
valid values
utc
system
this variable controls the time zone of timestamps in messages written to the error log, and in general query log and slow query log messages written to files. it does not affect the time zone of general query log and slow query log messages written to tables (mysql.general_log, mysql.slow_log). rows retrieved from those tables can be converted from the local system time zone to any desired time zone with convert_tz() or by setting the session time_zone system variable.
permitted log_timestamps values are utc (the default) and system (local system time zone).
timestamps are written using iso 8601 / rfc 3339 format: yyyy-mm-ddthh:mm:ss.uuuuuu plus a tail value of z signifying zulu time (utc) or ±hh:mm (an offset from utc).
修改参数就可以解决问题。
mysql> set global log_timestamps = system; query ok, 0 rows affected (0.00 sec) mysql> show global variables like 'log_timestamps'; +----------------+--------+ | variable_name | value | +----------------+--------+ | log_timestamps | system | +----------------+--------+
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。