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

后端 未结 6 729
Happy的楠姐
Happy的楠姐 2021-01-18 19:40

I have the following error message:

SQLSTATE[HY000] [2003] Can\'t connect to MySQL server on \'192.168.50.45\' (4)

How would I

相关标签:
6条回答
  • 2021-01-18 20:11

    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.

    0 讨论(0)
  • 2021-01-18 20:12

    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.)

    0 讨论(0)
  • 2021-01-18 20:16

    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.

    0 讨论(0)
  • 2021-01-18 20:25

    @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.

    0 讨论(0)
  • 2021-01-18 20:29

    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)

    0 讨论(0)
  • 2021-01-18 20:32

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

    0 讨论(0)
提交回复
热议问题