I see a lot of queries about how to connect a client to a MySQL server when the connection is refused or unsuccessful. In the interest of simplifying responses in the future
To connect from a client machine to a MySQL DB, the data has to traverse up to 5 levels of validation. Here's a general case where the client and server are not on the same network and a secure connection is not used:
First make sure MySQL is using a bind-address
that is different from localhost
so it uses an interface and not just local connections.
At each level, the firewall rules/permissions have to allow the connection to go through. Note that a machine can and often has a different IP internally than externally. The basic principle is:
The Client external IP has to be allowed to connect to the DB internal IP, through all the levels.
Most of the time, the firewalls are properly configured. The last piece often missing the MySQL server GRANT
ing permission to the DB
for the external user. The last syntax is:
MySQL Grant Syntax
Which often has the form:
GRANT ALL ON <DB>.* TO '<external_user>'@'<external_ip>' IDENTIFIED BY 'external_password';