how to understand “can't connect” mysql error messages?

大城市里の小女人 提交于 2019-12-01 18:00:18
cdhowie

HY000 is a very general ODBC-level error code, and 2003 is the MySQL-specific error code that means that the initial server connection failed. 4 is the error code from the failed OS-level call that the MySQL driver tried to make. (For example, on Linux you will see "(111)" when the connection was refused, because the connect() call failed with the ECONNREFUSED error code, which has a value of 111.)

Using the perror tool that comes with MySQL:

shell> perror 4
OS error code   4:  Interrupted system call

It might a bug where incorrect error is reported, in this case, it might a simple connection timeout (errno 111)

FWIW, having spent around 2-3 months looking into this in a variety of ways, we have come to the conclusion that (at least for us), the (4) error happen when the network is too full of data for the connection to complete in a sane amount of time. from our investigations, the (4) occurs midway through the handshaking process. You can see this in a unix environment by using 'netem' to fake network congestion.

The quick solution is to up the connection timeout parameter. This will hide any (4) error, but may not be the solution to the issue. The real solution is to see what is happeneing at the DB end at the time. If you are processing a lot of data when this happens, it may be a good ideas to see if you can split this into smaller chunks, or even pas the processing to a different server, if you have that luxury.

I happened to face this problem. Increase the connect_timeout worked out finally.

I was just struggling with the same issue.

Disable the DNS hostname lookups solved the issue for me.

[mysqld] ... ... skip-name-resolve

Don't forget to restart MySQL to take effect.

@cdhowie While you may be right in other circumstances, with that particular error the (4) is a mysql client library error, caused by a failed handshake. Its actually visible in the source code. The normal reason is too much data causing an internal timeout. Making 'room' for the connection normally sorts it without masking the issue, like upping the timeout or increasing bandwidth.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!