Connecting to MySQL Remotely
From A2Wiki
Our servers are behind a firewall which restricts remote access to the MySQL port (3306).
If you need to connect to MySQL from a remote computer, there are two options:
- Let us know what IP you'll be connecting from (you can find your external IP here:[1], and we can add an exception to our firewall to let you through. This solution will only work if you're connecting from a location with a static IP. Once a firewall exception is set up, you can use your domain name as the hostname for the MySQL server.
- If your account includes SSH access, you can set up an SSH tunnel to forward a port on your local computer to our MySQL server. We won't have to alter our firewall rules, and as an added bonus the MySQL traffic will be encrypted.
For the SSH approach, here's more info:
-
To ssh tunnel from a Mac OS X or *nix box, open a terminal and use the following:
ssh -p7822 mydomain.com -L 3306:localhost:3306
-
To SSH from a windows machine, we recommend putty Click to download.
Open Putty.
In the Category pane of the application window, select the "Tunnels" option found under Connection->SSH.
In the main pane, in the "Port Forwarding" section, do this:
1. Add the port that you would like to forward by Source Port(we chose 3306 for mysql).
2. By destination, type the hostname you want to connect to (most likely localhost).
3. At the end of the hostname, add a colon followed by 3306, like so: localhost:3306
4. Click add. It should then appear in the box under Forwarded Ports.
5. Click on the session in the category pane.
6. Enter the hostname your want to connect to (yourdomain.com) and the port as 7822
7. Click connect.
8. You can verify if PuTTY has set up the port forwarding correctly by looking at the PuTTY Event Log. To do this, click on the Windows icon in left corner of the menu bar in your open SSH session. There the drop down menu should show Event Log with other options. In the Event Log you should see something to the effect of: 2007-06-13 13:22:10 Local port 3360 forwarding to localhost:3306
For more information on Putty please see the Putty User Manual especially the section on Port Forwarding. - Please login to cpanel.
- Click on the MySQL icon
- In the access hosts field, you will need to put a "%" sign.
- Click the "Add Hosts" button
- You should now be able to connect to port 3306 at localhost and it will be fowarded to the remote mysql server.
Please note that we use port 7822 for SSH connections.
