Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 717
Itay Moav -Malimovka Avatar asked Jun 27 '12 16:06

Itay Moav -Malimovka


People also ask

How do I see MySQL error messages?

We can print the error message by using mysql function mysql_error(). This function returns the error message associated with most recently executed query. So it is a good idea to check for error before going to next query. We can even add the error number returned by mysql to this error message.

Why MySQL database is not connecting?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

How do I fix MySQL connection refused?

Check that the DB username, DB password, database host, and database port are correct. (if you are unsure, reach out to your database administrator or check in your web hosting account for the up to date credentials). If the config file references host = "localhost" , you can try to change it to 127.0.


2 Answers

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

like image 198
cdhowie Avatar answered Sep 28 '22 08:09

cdhowie


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)

like image 34
geertjanvdk Avatar answered Sep 28 '22 07:09

geertjanvdk