So, I have a problem in trying to talk to a remote MySQL server, which is on a Digital Ocean host (Ubuntu). My other host is on IPOWER, but their SQL capabilities are not so great so I wanted my PHP files on IPOWER to talk to my MySQL database on Digital Ocean.

I keep getting an error, "connection refused" however.

This is what it looks like from the IPOWER side:

mysqli_connect('$myDigitalOceanIP', '$myUserName', '$myPassword', 'database', '3306');

On the Digital Ocean side I have done the following:

  • Lifted the firewall and IPTables restrictions on port 3306

  • Created a new user in the MySQL that comports with $myUserName with Select, Insert, and Update permissions that can connect from any IP.

  • Flushed privileges in MySQL console and restarted the MySQL and Apache services

  • Confirmed that MySQL is listening on port 3306.

  • Edited the my.cnf file so that bind-address is commented out so that connections outside of the localhost can be accepted.

With all of this, I am still getting connection refused. Please throw additional suggestions my way!

Also, is there an error log I should be looking at? The Apache access and error logs yield me nothing and I couldn't find a SQL error log. Do I have to enable it somehow?

  • "Connection refused" is a lower level TCP error that will not directly be caused or logged by mysqld. netstat -a -n | grep 3306 to sanity check that you are indeed listening on – Michael - sqlbot Sep 22 '15 at 11:08
  • @Michael-sqlbot Putting that command in yields me the following, which I believe confirms I am listening on 3306: tcp 0 0* LISTEN – Summer Developer Sep 22 '15 at 13:13
  • You are indeed correct. It's listening as it should be. If the firewall on the server also looks good, verify that neither provider has any kind of firewalling on the connection -- inbound at the MySQL side, outbound at the PHP side -- that would be the next thing I would suspect, something intermediate is blocking you. See if you can just $ telnet digitaloceanip 3306 (from elsewhere, for testing). MySQL Server doesn't actually speak telnet, but you can connect with it for testing and see the semi-human-readable handshake packet, including the server version. – Michael - sqlbot Sep 22 '15 at 21:12
  • The step after that would be checking out tshark. Running it on the MySQL machine should help you confirm that packets aren't actually arriving. sudo tshark 'tcp port 3306'. You should not see the connection attempt if the packets are being blocked externally, but you would see them if your firewall is misconfigured. – Michael - sqlbot Sep 22 '15 at 21:15
  • @Michael-sqlbot tshark doesn't work for some reason, but digitalocean support says they can telnet at the 3306 port. – Summer Developer Sep 23 '15 at 4:48

It turns out I was doing everything right, the problem was on the IPOWER side. I had a friend remotely connect to the SQL server on Digital Ocean and he did so in five seconds.

The lesson here is don't let the customer choose the host, and don't use a crappy host like IPOWER that suggests you downgrade PHP and interferes with your remote connections for no reason.

Following the steps outlined in the question should resolve this for anyone in the future, so long as they use hosts that allow them to configure options themselves and don't intentionally try to mess with them.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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