how to understand "can't connect" mysql error messages?

Itay Moav -Malimovka picture Itay Moav -Malimovka · Jun 27, 2012 · Viewed 12.3k times · Source

I have the following error message:

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

How would I parse this (I have HY000, I have 2003 and I have the (4).

Answer

cdhowie picture cdhowie · Jun 27, 2012

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