最近遇到一个MySQL连接的问题,远程连接MySQL时遇到“ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0”错误,如下所示:
[[email protected] ~]# 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也会出现下面错误。
一般出现“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分析释疑”,但是当前这个案例中,不存在网络延时情况,如下所示:
[[email protected] ~]# ping 10.13.65.93PING 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 ms64 bytes from 10.13.65.93: icmp_seq=2 ttl=97 time=36.3 ms64 bytes from 10.13.65.93: icmp_seq=3 ttl=97 time=36.1 ms64 bytes from 10.13.65.93: icmp_seq=4 ttl=97 time=36.0 ms64 bytes from 10.13.65.93: icmp_seq=5 ttl=97 time=36.1 ms64 bytes from 10.13.65.93: icmp_seq=6 ttl=97 time=36.2 ms64 bytes from 10.13.65.93: icmp_seq=7 ttl=97 time=36.1 ms64 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 7003msrtt min/avg/max/mdev = 36.092/36.205/36.354/0.205 ms