Ubuntu – Connecting To Remote MySQL Server – Connection Refused

MySQLPHPremote-accessUbuntu

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?

Best Answer

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.