ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

MySQL5.7慢查询日志时间与系统时间差8小时原因

2020-01-10 15:00:30  阅读:319  来源: 互联网

标签:UTC log zone MySQL5.7 mysql 时间差 time timestamps 日志


在对慢查询进行查看的时候发现时间不对,正好与系统时间相差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 |
+----------------+--------+

标签:UTC,log,zone,MySQL5.7,mysql,时间差,time,timestamps,日志
来源: https://blog.51cto.com/roidba/2465841

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有