在使用mysql5.7的時候,發現了不少在mysql5.6上不曾見過的日志,級别為note, 最常見的note日志以下三種,下面我們來逐個解釋。
第一種,Aborted connection . 如上圖,資訊如下:
2020-08-17T14:44:24.102542Z 59 [Note] Aborted connection 59 to db: ‘unconnected’ user: ‘mha’ host: ‘10.xx.xx.xx’ (Got an error reading communication packets)
2020-08-17T14:44:31.273897Z 61 [Note] Aborted connection 61 to db: ‘unconnected’ user: ‘mha’ host: ‘10.xx.xx.xx(Got an error reading communication packets)
2020-08-17T14:44:31.273897Z 61 [Note] Aborted connection 61 to db: ‘unconnected’ user: ‘mha’ host: ‘10.xx.xx.xx(Got an error reading communication packets)
2020-08-17T14:44:31.273897Z 61 [Note] Aborted connection 61 to db: ‘unconnected’ user: ‘mha’ host: ‘10.xx.xx.xx(Got timeout reading communication packets)
上面兩個是連接配接中斷的錯誤資訊,原因不一樣,
Got an error reading communication packets 的原因是因為網絡等原因導緻。
Got timeout reading communication packets 這個錯誤的原因是會話的idle時間達到了資料庫指定的timeout時間。
關于Aborted connection告警日志的分析
2020-05-19閱讀 3470
前言:
有時候,連接配接MySQL的會話經常會異常退出,錯誤日志裡會看到"Got an error reading communication packets"類型的告警。本篇文章我們一起來讨論下該錯誤可能的原因以及如何來規避。
1.狀态變量Aborted_clients和Aborted_connects
首先我們來了解下Aborted_clients和Aborted_connects這兩個狀态變量的含義,當出現會話異常退出時,這兩個狀态值會有變化。根據官方文檔描述,總結如下:

造成Aborted_connects狀态變量增加的可能原因:
- 用戶端試圖通路資料庫,但沒有資料庫的權限。
- 用戶端使用了錯誤的密碼。
- 連接配接包不包含正确的資訊。
- 擷取一個連接配接包需要的時間超過connect_timeout秒。
造成Aborted_clients狀态變量增加的可能原因:
- 程式退出前,客戶機程式沒有調用mysql_close()。
- 用戶端睡眠時間超過了wait_timeout或interactive_timeout參數的秒數。
- 用戶端程式在資料傳輸過程中突然終止。
簡單來說即:資料庫會話未能正常連接配接到資料庫,會造成Aborted_connects變量增加。資料庫會話已正常連接配接到資料庫但未能正常退出,會造成Aborted_clients變量增加。
2.Got an error reading communication packets原因分析
哪種情況會導緻error log中出現“Aborted connection xxxx to db: 'db' user: 'dbuser' host: 'hostname' (Got an error reading communication packets)”類似告警呢?
下面我們根據上面可能的原因來做下具體測試。每次測試要注意狀态變量Aborted_clients和Aborted_connects的變化及錯誤日志記錄。
- 測試一:錯誤密碼,錯誤使用者
1.測試前檢視狀态變量值:
mysql> show global status like 'abort%';
+------------------+-------+| Variable_name | Value |+------------------+-------+| Aborted_clients | 0 |
| Aborted_connects | 0 |+------------------+-------+
2.測試過程# mysql -uroot -pwrongpassmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000):
Access denied for user 'root'@'localhost' (using password: YES)# mysql -uroot1 -pwrongpassmysql:
[Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000):
Access denied for user 'root1'@'localhost'
3.檢視狀态變化及錯誤日志:
mysql> show global status like 'abort%';
+------------------+-------+| Variable_name | Value |+------------------+-------+|
Aborted_clients | 0 || Aborted_connects | 2 |+------------------+-------+
錯誤日志記錄:2020-03-16T17:58:35.318819+08:00 6 [Note]
Access denied for user 'root'@'localhost' (using password: YES)
2020-03-16T17:59:04.153753+08:00 7 [Note] Access denied for user 'root1'@'localhost' (using password: YES)
結果:Aborted_connects有增加 error log無Aborted connection相關記錄
- 測試二:睡眠時間逾時或手動殺會話
1.測試前檢視狀态變量值:
mysql> show global status like 'abort%';
+------------------+-------+| Variable_name | Value |+------------------+-------+|
Aborted_clients | 0 || Aborted_connects | 2 |+------------------+-------+
2.手動殺會話測試:
mysql> show processlist;
+----+------+-----------+------+---------+------+----------+------------------+| Id | User | Host | db | Command | Time | State | Info
|+----+------+-----------+------+---------+------+----------+------------------+| 9 | root | localhost | NULL | Query | 0
| starting |
show processlist
|| 10 | root | localhost | NULL | Sleep | 7 | | NULL
|+----+------+-----------+------+---------+------+----------+------------------+
2 rows in set (0.00 sec)mysql> kill 10;Query OK, 0 rows affected (0.00