2021-02-02 15:26 发布至今 2021-08-19 16:30 终于得到解决办法:

经查阅资料得知:

1.mysql5.7log_warnings默认值是2https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html

log_warnings的值为0,表示不记录警告信息。
log_warnings的值为1,表示警告信息一并记录到错误日志中。
log_warnings的值大于1,表示"失败的连接"的信息和创建新连接时"拒绝访问"类的错误信息也会被记录到错误日志中。【实际生成环境值设为2会影响正常程序的连接,经常会断开与mysql的连接】
mysql5.5中log_warnings参数的默认值为1
mysql5.7中log_warnings参数的默认值为2

mysql5.7 报错Got an error reading communication packets 关于Aborted connection告警日志的分析

 

 2.在线修改log_warnings的值:

mysql> select @@log_warnings;
+----------------+
| @@log_warnings |
+----------------+
|              2 |
+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> set global log_warnings=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

3.但这样直接修改,重启后会失效,修改配置文件mysql.cnf   log_warnings = 1   【这样应该可以,没实际修改过】

==========================================

前言:

有时候,连接MySQL的会话经常会异常退出,错误日志里会看到"Got an error reading communication packets"类型的告警。本篇文章我们一起来讨论下该错误可能的原因以及如何来规避。

1.状态变量Aborted_clients和Aborted_connects

首先我们来了解下Aborted_clients和Aborted_connects这两个状态变量的含义,当出现会话异常退出时,这两个状态值会有变化。根据官方文档描述,总结如下:

造成Aborted_connects状态变量增加的可能原因:

  1. 客户端试图访问数据库,但没有数据库的权限。
  2. 客户端使用了错误的密码。
  3. 连接包不包含正确的信息。
  4. 获取一个连接包需要的时间超过connect_timeout秒。

造成Aborted_clients状态变量增加的可能原因:

  1. 程序退出前,客户机程序没有调用mysql_close()。
  2. 客户端睡眠时间超过了wait_timeout或interactive_timeout参数的秒数。
  3. 客户端程序在数据传输过程中突然终止。

简单来说即:数据库会话未能正常连接到数据库,会造成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' (using password: YES)
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 (

相关文章: