Tunnelling through PuTTY to MySQL, using SQLyog

Let’s say you have a shared web hosting account on a random cheap provider, and the only way to access the MySQL server is to either connect from an SSH command line or use phpMyAdmin. While both of these options are okay, in some circumstances it’s not exactly wise to have a phpMyAdmin installation publically accessible, as it lends itself to repeated bruteforce attacks and is subject to server configuration changes. I know on my personal server, there have often been times that I’ve inadvertently left a myAdmin installation wide open for anyone to monkey with the database.

I also enjoy using an application called SQLyog, which is a Windows GUI tool for managing MySQL databases. The Community Edition of the application has proven to be more than sufficient for my random projects, and I highly suggest anyone doing database work on Windows take a look at the application.

Using some details from this article, with an updated version of PuTTY, here’s how I go about configuring my local system to connect to a remote MySQL server:

Start PuTTY:
PuTTY 01

Define your connection settings and save them:
PuTTY 02

Navigate to the Connection / SSH / Tunnels view, and provide the following settings:

Source Port: 3306
Destination: localhost:3306
(This assumes you don’t have a MySQL server running on your local machine. If you do, change localhost:3306 to localhost:freeport where freeport is the number of a free port on your workstation.)

PuTTY 03

Click the Add button, then save your connection settings. In the Forwarded Ports list, you should see L3306 localhost:3306.
Open the connection and sign in to the remote system.
PuTTY 04
Start SQLyog and define a connection to localhost:3306.
PuTTY 05
Your connection will be tunnelled through SSH to the remote server transparently. Make sure that you close SQLyog before you close the PuTTY tunnel.
PuTTY 06

Let me know how this works for your development situations – even if you have direct access to the MySQL server, you should still check out SQLyog for database development if you haven’t already tried it.

4 Comments

Comments are closed.