Jacques Amar
Jacques Amar

Reputation: 1833

Successfully connect Client to MySQL server

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, I am going to post a simple diagram of connection needs at the IP and MySQL Level. I will add description to each section when need be.

Upvotes: 0

Views: 304

Answers (1)

Jacques Amar
Jacques Amar

Reputation: 1833

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.

MySQL Connection Needs

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 GRANTing 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';

Upvotes: 2

Related Questions