tags:

views:

82

answers:

2

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.

+1  A: 

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.
Rudu
Hi Rudi, thanks for the response!... 1. Yup, 2. 3306, 3. No firewall, as far as I can tell, 4. No NAT, direct IP, 5. bind-address is set and skip-networking is removed.
Julian H. Lam
In that case: `ping <mysql server ip>` - check you get a response. `telnet <mysql server ip> 3306` - should output a version string (it won't work right, but it'll give you a clue if it's running). Also check that the daemon is actually running on the server (how depends on win/linux)
Rudu
Some good points in the answer, Rudu, thanks. The problem turned out to be a bonehead config var on my part - I had set the "bind-address" to an internal IP, and expected it to work externally. Chalk one up to a tired Friday afternoon...
Julian H. Lam
It seems so obvious the next day - but you can spend hours trying to find a bug like that. Glad it's sorted.
Rudu
+1  A: 

It definitely sounds like the client isn't able to connect. This page has some suggestions on how to narrow down the problem:

http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html

What happens if you try to telnet to port 3306 on the server? You should get a prompt from MySQL.

mr. w
I ended up trying to connected via command line: `mysql --host=foobar`, and even that didn't work, which clued me in a little.
Julian H. Lam