Unable to connect to remote MySQL server

December 15, 2017 1.9k views
MySQL DigitalOcean Ubuntu 16.04

I am trying to connect to remote MySQL server from my local PC. I am getting "10061" error.

Here are the steps I followed:

  • changed the bind-address in file /etc/mysql/mysql.conf.d/mysqld.conf to the droplet ip.
  • GRANT ALL ON databasename.* TO user@xx.xxx.xx.xx IDENTIFIED BY 'yourpassword';
  • flush privileges;
  • sudo /etc/init.d/mysql restart

I have disabled firewall too. But still not able to connet to it. One more thing I have a live site using the same MySQL database, changing bind-address to droplet IP makes the server throw Internal Server Error. Why is that ?

1 Answer

One more thing I have a live site using the same MySQL database, changing bind-address to droplet IP makes the server throw Internal Server Error.

This is because Bind Address defines on what network interface MySQL listens for connections.
By default, it's set to 127.0.0.0 (i.e. localhost), which means you'll be able to access MySQL only using that address.

Changing Bind Address to Droplet's IP will instruct MySQL to listen for connection only via IP. In that case, you will not be able to access MySQL over 127.0.0.0 or localhost and your application will probably fail.

The solution is to set Bind Address to 0.0.0.0 allowing you to access MySQL via any (IPv4) network interface. Now, you can access to MySQL from using all addresses, including 127.0.0.0, localhost and Droplet's Public IP.

Make sure to restart MySQL after you're done with changes, to put them in the effect.

Also, what IP address you provided in that GRANT command? Is it Droplet's IP or you local one? You can also use % instead of an IP to allow access from any IP. It's not recommended to use % though, as it's insecure, but sometimes easier, such as when you have dynamic IP.

Have another answer? Share your knowledge.