【MySQL技术专题】「问题实战系列」MySQL报错Got an error reading communication packets问题分析指南
文章目录
- 前因背景
- 官方解释
- Aborted_connects:
- Aborted_clients:
- Aborted_connects OR Aborted_clients:
- 临时配置解决办法
- 设置最大包大小
- 查看包大小
- 永久配置解决办法
- 从以下几个方面考虑:
- TIME_WAIT的处理方案
- 网络问题分析
- mysql的参数设置:
- log_warnings掩耳盗铃
前因背景
当系统服务的MySQL错误日志中,发现大量以下类似信息:经常收到客户关于通信故障错误的问题—客户面临间歇性的”Got an error reading communication packet”错误,这里分析这个错误出现的原因,以及如何解决这个问题。
Aborted connection 1055898 to db: 'xxx' user: 'yyy' host: 'xxx.xxx.xxx.xxx' (Got timeout reading communication packets)
官方解释
下面看看官网怎么说:
Aborted_connects:
If a client is unable even to connect, the server increments the Aborted_connects status variable.
A client attempts to access a database but has no privileges for it.
#客户端没有权限但是尝试访问MySQL数据库
A client uses an incorrect password.
#客户端输入的密码有误。
A connection packet does not contain the right information.
#连接包不包含正确信息
takes more than connect_timeout seconds to obtain a connect packet.
#超过连接时间限制,主要是这个系统变量connect_timeout控制(mysql默认是10s,基本上,除非网络环境极端不好,一般不会超时。)
Aborted_clients:
lIf a client successfully connects but later disconnects improperly or is terminated, the server increments the Aborted_clients status variable
The client program did not call mysql_close() before exiting…
#客户端没有进行关闭
The client had been sleeping more than wait_timeout or interactive_timeout seconds without issuing any requests to the server.
#客户端睡眠时间超过了wait_timeout或interactive_timeout秒,而没有向服务器发出任何请求。
The client program ended abruptly in the middle of a data transfer.
#客户端程序在数据传输过程中突然终止。
Aborted_connects OR Aborted_clients:
Other reasons for problems with aborted connections or aborted clients:
the max_allowed_packet variable value is too small or queries require more memory than you have allocated for mysqld
#max_allow_packet设置过小
Use of Ethernet protocol with Linux, both half and full duplex. Some Linux Ethernet drivers have this bug
#Linux以太网驱动程序有这个bug
A problem with the thread library that causes interrupts on reads.#线程库中导致读取中断的问题。
Badly configured TCP/IP. #tcp/iip 配置信息混乱
Faulty Ethernets, hubs, switches, cables, and so forth. This can be diagnosed properly only by replacing hardware.
#故障的以太网、集线器、交换机、电缆等等
https://dev.mysql.com/doc/refman/5.7/en/communication-errors.html
Aborted connection情况下,这也意味着以下几个问题:
- 客户端正常连接,但是被异常结束(可能是程序没有正常关闭连接)
- 客户端sleep的时间超过了wait_timeout、或interactive_timeout的值(这会导致连接被mysql强制关闭)
- 客户端异常终端,或者查询超出max_allowed_packet的值
临时配置解决办法
设置最大包大小
set global max_allowed_packet = 1024*1024*1024;
查看包大小
mysql> show variables like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 16777216 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
永久配置解决办法
[mysqld]
max_allowed_packet=256M
当然,也可能是其它原因导致的。坦白讲,异常中断是很难诊断的,也有可能是和网络、防火墙有关。
从以下几个方面考虑:
- 如果有大量的连接进程处于sleep状态时间较长,也就意味着应用没有正确、及时关闭数据库连接。强烈建议在应用中能恰当地关闭数据库连接,否则就需要依赖mysql的wait_timeout的设置来关闭连接了。
- 建议检查max_allowed_packet的值,确保该值设置的合理,这样客户端就不会接收到"packet too large"消息提示。如果设置不合理,会异常中断连接。
- 建议关注线程的time_wait数量。如果netstat发现有大量的连接处于time_wait状态,表示该建议应用端调整连接关闭问题了。
TIME_WAIT的处理方案
netstat -ano|grep TIME_WAITtcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55586 TIME_WAIT timewait (32.97/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55367 TIME_WAIT timewait (27.82/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55776 TIME_WAIT timewait (37.09/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:56505 TIME_WAIT timewait (54.61/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55553 TIME_WAIT timewait (31.94/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:56643 TIME_WAIT timewait (57.73/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55221 TIME_WAIT timewait (23.70/0/0)
tcp 0 0 xxx.xxx.xxx.xxx:10054 xxx.xxx.xxx.xxx:55920 TIME_WAIT timewait (41.18/0/0)
网络问题分析
检查DNS配置是否有延迟问题。
- 检查是否同时配置了skip_name_resolve,且使用IP验证主机而不是使用主机名。设置该参数后,使用ip验证主机,而不是使用主机名。使用该参数后,mysql授权表中的host列必须是IP地址或者localhost。
增加net_read_timeout、net_write_timeout的值,并观察是否还有该错误发生;
- net_read_timeout很少会导致出错,除非网络环境非常差。
mysql的参数设置:
mysql> show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| interactive_timeout | 1800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| wait_timeout | 1800 |
+-----------------------------+----------+
- 连接异常中断是因为连接没有被正常关闭。
- server端不会导致连接abort,除非客户端/服务器端发生了网络问题。而不是server端的问题。
tcpdump,netstat -s
log_warnings掩耳盗铃
mysql> show global variables like '%log_warning%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings | 2 |
+---------------+-------+
1 row in set (0.00 sec)
如果log_warnings的值大于1,mysql会将类似信息写入错误日志:
[Warning] Aborted connection 305628 to db: 'db' user: 'dbuser' host: 'hostname' (Got an error reading communication packets)
[Warning] Aborted connection 305627 to db: 'db' user: 'dbuser' host: 'hostname' (Got an error reading communication packets)
可以修改一下log_waring的值:
set global log_warnings=1;
但这样直接修改,重启后会失效,修改配置文件mysql.cnf log_warnings = 1
【MySQL技术专题】「问题实战系列」MySQL报错Got an error reading communication packets问题分析指南相关推荐
- Mysql报错:Got an error reading communication packets
一.故障说明 某次一线巡检过程中发现,上午8点.9点左右kafka消息积压数异常增加,且同时Mysql数据库主从同步异常,测试数据库远程登录报错:Host -- is blocked because ...
- 完美解决MySQL错误日志出现大量的 Got an error reading communication packets 报错
最近在安装完mysql之后发现error log 出现大量 Got an error reading communication packets 等的读写报错,如下图 问题分析 其实Aborted c ...
- 【MySQL】Got an error reading communication packets
参考资料 MySQL"读取通信数据包时出错" Got an error reading communication packets
- mysql系统调优之Aborted connection timeout/error reading communication packets 错误解决
背景 近期客户的大数据任务调度应用系统出现问题,调度任务失败,任务没有正常执行,产品组同事去看应用日志也没发现错误日志.后来检查msql server日志 发现有很多节点连接报 error readi ...
- mysql提示Got timeout reading communication packets、Got an error reading communication packets
1,数据包太大 通信数据包是发送到MySQL服务器的单个SQL语句,发送到客户端的单个行或从复制源服务器发送到副本的二进制日志事件. 可以传输到MySQL 5.7服务器或客户端或从MySQL 5.7服 ...
- 【深入浅出Spring原理及实战】「开发实战系列」带你看看那些可能你还不知道的Spring特殊技巧和想不到的招数
前提介绍 本文主要介绍相关Spring框架的一些新特性问题机制,包含了一些特定注解方面的认识. @Lazy可以延迟依赖注入 @Lazy注解修饰在类层面! @Lazy @Service public c ...
- 【Java进阶营】Java技术专题「难点-核心-遗漏」Java线程状态流转及生命周期的技术指南(知识点串烧)
前提介绍 本章主要介绍相关线程声明周期的转换机制以及声明周期的流转关系以及相关AQS的实现和相关的基本原理,配合这相关官方文档的中英文互译的介绍. 线程状态流转及生命周期 当线程被创建并启动以后,它既 ...
- 宝塔mysql远程链接_宝塔apache启动失败:报错 AH00526: Syntax error on line 解决方案
错误信息: AH00526: Syntax error on line 54 of /www/server/apache/conf/httpd.conf: Cannot define multiple ...
- 「春招系列」30张图理解HTTP在面试中所有会出现的题
前言 又是一年金三银四,春招与跳槽热闹的开展着,而在面试过程中,HTTP 被提问的概率还是非常高的. 我搜集了 5 大类 HTTP 面试常问的题目,同时这 5 大类题跟 HTTP 的发展和演变关联性是 ...
最新文章
- hdu-4302-Holedox Eating-线段树-单点更新,有策略的单点查询
- spark1.1.0学习路线
- 一个好的网站,应该用什么样的空间or服务器?建站基础知识普及
- android23 imei 权限,android------关于API 23的权限问题
- POJ 1423 Big Number
- LDC1000学习资料
- SM30 - SMOFOBJECT
- 部署项目的问题(一)—— vue工程打包上线样式错乱问题
- python 文件和目录 当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径。
- BZOJ1729: [Usaco2005 dec]Cow Patterns 牛的模式匹配
- python动态调用自定义模块_python importlib动态导入模块 reload重载模块
- Codevs 1215 迷宫
- Structs 2 session 学习
- 神经网络——深度学习应用于计算机视觉
- J2ME移动开发平台搭建篇
- 第二阶段-面向对象(四)
- excel切片器显示错误_使用切片器在Excel中设置过滤条件
- google maps v3 电子地图测距
- 遇上爱发牢骚的同事怎么办?
- python 如何绘制ppt折线图