SSH Tunneling to mysql server using Putty

 I’ve had this question a couple of times in the past few months (since I posted the command line version of this method here ). To make it short and sweet, yes you can use Putty in a windows environment to setup ssh tunnels. Here is the specific scenario with pics for setting up a tunnel to your mysql server (assuming mysql server is running on a machine that you have ssh access to) using putty. This allows you to run mysql-gui-tools under windows and connect thru ssh to your server, without having to open the server to accept connections from the network.

  1. Download Putty full install package 
  2. Run putty and your’ll see the following screen. Fill in the hostname of the DB server and choose SSH as protocol.
  3. Go down to SSH and Tunnels options. Fill in 3306 for Source port, for local Destination port and click Add. This will forward (through SSH) all traffic sent to (aka. localhost:3306) to the remote host’s (DB Server) port 3306. You’ll see how this works in a second.
  4. Now go back to Sessions, Give the session a meaningful name (eg: MYSQLTunnel) and click Save so that it’s saved.

So now you’re done. If you need to access your mysql server, first run putty, load the session we just saved, connect and you’re good to go. You can use any network based mysql frontend and even the ODBC connector under windows and point them at host: and port: 3306, the SSH tunnel will then take the traffic and safely transfer it to your mysql server box. This way you can run your mysql server in local mode — where it will not accept connections from outside network — for safety reasons and have network access to it when you need.

, , ,

One response to “SSH Tunneling to mysql server using Putty”

  1. Excellent tutorial. Was excatly was I was looking for to remote connect to my db.

Leave a Reply