"Can't connect to MYSQL server" error. The DB is a separate server. http://dpaste.com/99702/

I typed "nc dbserver 3306" and it returned: [XXXXXX] 3306 (mysql) : Connection refused

Even in my GRANT options, I specified GRANT ALL TO . %...

My friend said that the web server is being prevented from establishing a TCP connection of any kind to that port.

I checked my.cnf...nothing special there. Could it be because of my IPTABLES? --skip-networking option is NOT in my.cnf.

Thank you

link|improve this question

feedback

4 Answers

up vote 0 down vote accepted

111 usually is a generic "socket" connect error, i.e. the packet never made it there. Without more info about how your firewall is set up, it could be caused by:

  • Bad IP address
  • Bad Port number (no service is running at that port)
  • Bad routing setup (rare, but happens)
  • Firewall is absorbing or rejecting the packet. This is most likely.

Try connecting with a firewall exception and see if that works. The exception should allow all traffic between the IP addresses of both machines, so there will be two rules - one for ingress and one for egress.

link|improve this answer
feedback

Connection refused means it's not listening on your external IP address. I know you said you'd looked at your my.cnf, but make sure you do not have any of the following lines:

bind-address            = 127.0.0.1
skip-networking

If you have bind-address, change it to be

bind-address            = *

If you have skip-networking, remove it.

If you've done these things, then check your firewall.

link|improve this answer
Thank you for this answer. I had a similar problem as the OP and found this. In my case, bind-address = * did not work. The server wouldn't restart. I removed the line altogether and now it works. I still need to investigate the security implications... – augustin Oct 27 '10 at 10:48
feedback

First thing to check : try to connect on the PC with MySQL.

Here's what I'd do to check where the error comes from :

  1. Try to connect directly : mysql -h 127.0.0.1 -u [username] -p[password]
  2. Try to connect directly with the external IP and the command line still on the MySQL computer : mysql -h 192.168.0.26 -u [username] -p[password]
  3. Try to connect using command line from a distinct PC : mysql -h 192.168.0.26 -u [username] -p[password]
  4. If everything works, the problems comes from the Apache Server configuration. Otherwise you'll be able to quickly guess where the problem comes from.
link|improve this answer
Sorry for the 4th : it may comes from the Apache Server configuration or the firewall where the Apache Server is. – Olivier Pons Sep 29 '09 at 7:21
feedback

First and foremost, ensure that your MySQL server is actually listening on an external TCP socket. Do a netstat and see if you get something with 3306 in it and make sure that it is not just 127.0.0.1:3306 or something local like that.

# netstat -untap | grep 3306

Sometimes, MySQL is by default configured to listen only on local sockets. If that is the case, just edit your my.cnf file to listen on all interfaces. Otherwise, it is likely a networking problem.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.