1. 程式人生 > >解決mysql日誌顯示時間和“Got an error reading communication packets” 問題

解決mysql日誌顯示時間和“Got an error reading communication packets” 問題

[[email protected] data]# tail -f mysql.error
2018-11-26T22:13:12.884160Z 4928033 [Note] Aborted connection 4928033 to db: 'calldb' user: 'call' host: '172.31.50.220' (Got an error reading communication packets)
2018-11-26T22:13:12.884160Z 4928083 [Note] Aborted connection 4928083 to db: 'calldb' user: '
call' host: '172.31.50.220' (Got an error reading communication packets) 2018-11-26T22:13:12.884172Z 4848700 [Note] Aborted connection 4848700 to db: 'calldb' user: 'call' host: '172.31.50.220' (Got an error reading communication packets) 2018-11-26T22:13:21.228059Z 4771072 [Note] Aborted connection 4771072 to
db: 'calldb' user: 'call' host: '172.31.50.221' (Got an error reading communication packets) 2018-11-26T22:13:21.228081Z 4926711 [Note] Aborted connection 4926711 to db: 'calldb' user: 'call' host: '172.31.50.221' (Got an error reading communication packets) 2018-11-26T22:13:21.228084Z 4928159 [Note] Aborted connection 4928159
to db: 'calldb' user: 'call' host: '172.31.50.221' (Got an error reading communication packets) 2018-11-26T22:13:21.228213Z 4926592 [Note] Aborted connection 4926592 to db: 'calldb' user: 'call' host: '172.31.50.221' (Got an error reading communication packets) 2018-11-27T00:23:08.438660Z 4968411 [Note] Aborted connection 4968411 to db: 'calldb' user: 'call' host: 'vpn.g5air.com' (Got timeout reading communication packets) 2018-11-27T00:23:24.822669Z 4968419 [Note] Aborted connection 4968419 to db: 'calldb' user: 'call' host: 'vpn.g5air.com' (Got timeout reading communication packets)

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

注意到日誌時間顯示不正確,故需改成北京時間

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.00 sec)

修改之後如下。日誌好看多了

2018-11-27T09:23:11.153618+08:00 4974498 [Note] Aborted connection 4974498 to db: 'hcalldb' user: 'hcall' host: '172.31.86.43' (Got an error reading communication packets)
2018-11-27T09:26:22.312188+08:00 4974583 [Note] Aborted connection 4974583 to db: 'hcalldb' user: 'hcall' host: '172.31.86.43' (Got an error reading communication packets)

解決 “Got an error reading communication packets” 問題

mysql> show global status like '%abort%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Aborted_clients  | 6644  |
| Aborted_connects | 66042 |
+------------------+-------+
2 rows in set (0.00 sec)

  

Aborted_clients #表示有一個連線的mysql客戶端被連線被kill的數量,MYSQL認為讀到了一個錯誤的包,並將該連線Aborted

模擬:

在linux下開啟多個客戶端,每個客戶端登入mysql,然後我們在其中的一個linux客戶端下,強制kill其他mysql客戶端登入程序,同時監控error_log情況,即可出現上面日誌情況。

Aborted_connects #表示有客戶端因為密碼或其他什麼原因登入失敗的數量