• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

MySQL Aborted connection告警日志的分析

mysql 搞代码 4年前 (2022-01-09) 15次浏览 已收录 0个评论

前言:

有时候,连接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. 程序退出前,客户机程序没有本文来源gaodai$ma#com搞$$代**码)网8调用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 (0.00 sec)
3.查看状态变化及错误日志mysql> show global status like 'abort%';+------------------+-------+| Variable_name  | Value |+------------------+-------+| Aborted_clients | 1   || Aborted_connects | 2   |+------------------+-------+
结果:Aborted_clients有增加 error log无记录 ,类似的,睡眠时间超时后Aborted_clients有增加 error log中有Aborted connection相关记录。

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:MySQL Aborted connection告警日志的分析

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址