Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to remote MySQL Server

Tags:

mysql

I have a server attempting to connect to a MySQL database hosted outside of the local network. I am attempting to use a public IP address to connect to it.

Testing the connection in the command line gives me this error:

ERROR 2003 (HY000): Can't connect to MySQL server on '[ip_address]' (146)

PDO gives me the same error. In any case, the connection works fine locally and within the same network, which is what boggles my mind.

The MySQL server has had its bind-address modified so it accepts remote connections. The MySQL server also has a user with the proper privileges set. But in any case, it looks as though I can't even start the connection in the first place.

Is there a my.cnf value I need to add to let MySQL accept requests from outside the local network?

Thanks.

like image 514
Julian H. Lam Avatar asked Sep 10 '10 16:09

Julian H. Lam


People also ask

Why MySQL server 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.


2 Answers

Things to check:

  1. MySQL is listening on public IP (sounds like you've done)
  2. MySQL is listening on standard port / you're connecting the same port it's listening to.
  3. Is there a firewall running on the remote machine? (They usually are packaged standard in distros) Is the firewall configured to allow connections to that port?
  4. If the remote machine is within another network, is there network address translation (NAT) going on between your connection and the end machine - if so, is it configured to allow the MySQL port through.
  5. Is the my.cnf file configured to allow connections from anything other than localhost 127.0.0.1 IPs - although you'd more likely get a access denied response, than a cannot connect.
like image 54
Rudu Avatar answered Nov 14 '22 09:11

Rudu


grant privileges to the user from that particular host. or to access it from any host use % (i.e. wild card) as host.

like image 24
Sandesh Avatar answered Nov 14 '22 09:11

Sandesh