温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MySQL慢查询日志时间与系统不一致的解决方法

发布时间:2020-06-06 22:28:42 来源:亿速云 阅读:999 作者:Leah 栏目:MySQL数据库

如何解决MySQL慢查询日志时间与系统时间相差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 |
+----------------+--------+

以上就是慢查询日志时间与系统不一致的解决方法,详细使用情况还需要大家自己亲自动手使用过才能领会。如果想了解更多相关内容,欢迎关注亿速云行业资讯频道!



                                                          

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI