Attempting to connect to remote MySQL server produces the below error.
ERROR 2003 (HY000): Can't connect to MySQL server on
In order to connect to the remote server, and do so securely it is best to create an SSH tunnel with a port forward and THEN connect as though it were a localhost.
Things to note:
Probably best to forward a port you’re not using. It is likely (esp if you are using linux) that port 3306 (default MySQL port) is already being used.
Using the word localhost causes issues . use your bind address (usually 127.0.0.1)
FIRST
SSh into the server that is running the MySQL service.
The below example assumes:
127.0.0.1 is your servers bind address. If your my.cnf is set to only listen to local host, it most likely is.
That your MySQL server is listening on port 3306
SSH -L 7788:127.0.0.1:3306 user@server.com
Once you have established a connection you can connect using 127.0.0.1 as the host, and (in this example) 7788 as the port.
Leave a Reply