Mysql5.7慢日志時間與系統時間相差8小時問題的解決


一、msyql5.7開啟慢日志后發現日志的時間與系統時間相差8小時

[root@zabbix_server mysql]# vim zabbix_server-slow.log 

 17  LIMIT 0, 1000;
 18 # Time: 2020-04-07T09:16:18.175882Z
 19 # User@Host: root[root] @ zabbix_server [172.28.18.75]  Id: 5815703
 20 # Query_time: 0.105811  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 0
 21 use slow_query_log;
 22 SET timestamp=1586250978;
 23 CREATE TABLE `global_query_review` (
  1 
  2 # Time: 2020-04-07T06:34:40.688996Z
  3 # User@Host: root[root] @ zabbix_server [172.28.18.75]  Id: 5815703
  4 # Query_time: 0.293296  Lock_time: 0.000120 Rows_sent: 1  Rows_examined: 0
  5 SET timestamp=1586241280;
  6 select count(*) from history_log;
  7 # Time: 2020-04-07T06:38:39.484322Z
  8 # User@Host: root[root] @ zabbix_server [172.28.18.75]  Id: 5815703
  9 # Query_time: 91.377653  Lock_time: 0.000102 Rows_sent: 1  Rows_examined: 15267776
 10 SET timestamp=1586241519;
 11 select count(*) from trends;
Time: 2020-04-07T06:34:40.688996Z,實際時間應該是14:34:40
這是由於log_timestamps這個參數設置造成的,查詢當前設置
mysql> show variables like '%log_time%';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| log_timestamps | UTC   |
+----------------+-------+
1 row in set (0.01 sec)

UTC是世界統一時間,而我現在的系統為北京時間是東八區,比UTC早了8個小時,所以這里設置為SYSTEM

mysql> set global log_timestamps=SYSTEM;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%log_time%';
+----------------+--------+
| Variable_name  | Value  |
+----------------+--------+
| log_timestamps | SYSTEM |
+----------------+--------+
1 row in set (0.01 sec)

在mysql里執行一條測試慢日志語句

mysql> select sleep(5);
+----------+
| sleep(5) |
+----------+
|        0 |
+----------+
1 row in set (4.99 sec)

mysql> 

再次查看慢日志

 51  LIMIT 0, 1000;
 52 # Time: 2020-04-08T14:25:16.200913+08:00
 53 # User@Host: root[root] @ zabbix_server [172.28.18.75]  Id: 5870204
 54 # Query_time: 5.000269  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
 55 use slow_query_log;
 56 SET timestamp=1586327116;
 57 select sleep(5);
[root@zabbix_server mysql]# 

時間跟系統時間一樣了。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM