设为首页 加入收藏

TOP

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0(一)
2019-09-17 17:21:38 】 浏览:25
Tags:ERROR 2013 HY000 Lost connection MySQL server ' reading authorization packet' system error:

最近遇到一个MySQL连接的问题,远程连接MySQL时遇到ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0错误,如下所示:

 

[root@DB-Server ~]# mysql -h 10.13.65.93 -u onecard -p

Enter password:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0

 

这个测试的MySQL位于阿里云Kubernetes(K8s)中Docker容器里面,而且在远程连接MySQL出现上面错误的时候,Docker也会出现下面错误。

 

clip_image001

 

一般出现ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet'错误的原因较多:

 

1:网络异常或时延非常高的时候, 超过连接时间限制(系统变量connect_timeout)会导致这个错误。MySQL客户端与数据库建立连接需要发起三次握手协议,正常情况下,这个时间非常短,但是一旦网络异常,网络超时等因素出现,就会导致这个握手协议无法完成,MySQL有个参数connect_timeout,它是MySQL服务端进程mysqld等待连接建立完成的时间,单位为秒。如果超过connect_timeout时间范围内,仍然无法完成协议握手话,MySQL客户端会收到异常。  更多详细信息可以参考我这篇博客MySQL参数max_connect_errors分析释疑,但是当前这个案例中,不存在网络延时情况,如下所示:

 

[root@DB-Server ~]# ping 10.13.65.93
PING 10.13.65.93 (10.13.65.93) 56(84) bytes of data.
64 bytes from 10.13.65.93: icmp_seq=1 ttl=97 time=36.1 ms
64 bytes from 10.13.65.93: icmp_seq=2 ttl=97 time=36.3 ms
64 bytes from 10.13.65.93: icmp_seq=3 ttl=97 time=36.1 ms
64 bytes from 10.13.65.93: icmp_seq=4 ttl=97 time=36.0 ms
64 bytes from 10.13.65.93: icmp_seq=5 ttl=97 time=36.1 ms
64 bytes from 10.13.65.93: icmp_seq=6 ttl=97 time=36.2 ms
64 bytes from 10.13.65.93: icmp_seq=7 ttl=97 time=36.1 ms
64 bytes from 10.13.65.93: icmp_seq=8 ttl=97 time=36.2 ms
 
--- 10.13.65.93 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7003ms
rtt min/avg/max/mdev = 36.092/36.205/36.354/0.205 ms

 

clip_image002

 

 

 

2:域名解析会导致这个问题。当客户端连接上来,服务器端都会对客户端进来的IP地址进行DNS解析,来获得客户端的域名或主机名,如果DNS解析出了问题或DNS解析相当慢,就会导致连接验证用户出现问题。而skip-name-resolve这个参数的意义就是禁止域名解析。官方文档解释如下:

 

 

For each new client connection, the server uses the client IP address to check whether the client host name is in the host cache. If so, the server refuses or continues to process the connection request depending on whether or not the host is blocked. If the host is not in the cache, the server attempts to resolve the host name. First, it resolves the IP address to a host name and resolves that host name back to an IP address. Then it compares the result to the original IP address to ensure that they are the same. The server stores information about the result of this operation in the host cache. If the cache is full, the least recently used entry is discarded.

The server handles entries in the host cache like this:

 

  • When the first TCP client connection reaches the server from a given IP address, a new cache entry is created to record the client IP, host name, and client lookup validation flag. Initially, the host name is set to NULL and the flag is false. This entry is also used for subsequent client TCP connections from the same originating IP.

 

 当有一个新的客户端连接通过TCP进来时,MySQL Server会为这个IP在host cache中建立一个新的记录,包括IP,主机名和client lookup validation flag,分别对应host_cache表中的IP,HOST和HOST_VALIDATED这三列。第一次建立连接因为只有IP,没有主机名,所以HOST将设置为NULL,HOST_VALIDATED将设置为FALSE。

 

  • If the validation flag for the client IP entry is false, the server attempts an IP-to-host name-to-IP DNS resolution. If that is successful, the host name is updated with the resolved host name and the validation flag is set to true. If resolution is unsuccessful, the action taken depends on whet
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL数据库笔记二:数据类型及数.. 下一篇深入理解Mysql索引底层数据结构与..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目