First of all, you have to edit mysql configuration file

nano /etc/mysql/my.cnf

So, you have to change bind-address key to droplet ip instead of (Local Only)

bind-address = YOUR_DROPLET_IP

Restart Mysql Service to apply changes

sudo service mysql restart

Now, you have to allow mysql port on ufw firewall

sudo ufw allow 3306/tcp

This will enable rules for IPV4 and IPV6 both

Now let's create an user on Mysql, the host will be your droplet ip instead of @localhost

CREATE USER 'newuser'@'your_droplet_ip' IDENTIFIED BY 'password';

Grant permission you want, in my case, i want grant permission for all databases for this user

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'your_droplet_ip';

Don't forget to reload mysql privileges running


Restart mysql to ensure changes will be applied

sudo service mysql restart

It's done, now you have a database with remote access via standard tcp, you will be able to connect with your mysql just providing host, user and password.

Be aware this approach is not safe for production applications, it must be used in special cases. For production applications restrict database access only for local requests.

Por Marcos Mendes @marcoshmendes