Tunneling MySQL ports through SSH

From CS Support
Jump to: navigation, search

Setting up an SSH tunnel with PuTTY in Windows

The following instructions will show you how to setup an SSH tunnel using Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/, to forward the default MySQL port (3306) from your machine through another machine behind a firewall to the MySQL server. This allows you to connect to the remote server's MySQL database as if it were running on your local box, and will traverse any firewalls that block port 3306, but allow port 922.

Setting up the tunnel

Run PuTTY

  1. Under category expand Connection
  2. Expand SSH
  3. Select Tunnels
  4. Select Source port and enter 3306
  5. Select Destination and enter mysql.cs.wwu.edu:3306
  6. Make sure the Local and Auto radio buttons are selected
  7. Select Add

File:Putty config2.png

Your options should now look like the following.

File:Putty config3.png

Saving the Session

  1. Under category selectSession
  2. Select Host Name (or IP address) and enter username@linux.cs.wwu.edu, this will connect you through one of the remote linux machines.
  3. Make sure Port is set to 922
  4. Select Saved Session and enter a name
  5. Select Save
  6. Select Open to connect to the server

File:Putty config.png

Using the Connection

You can now specify your MySQL server as being 127.0.0.1 with port 3306, with whatever you are using to connect to the database.

Setting up an SSH tunnel in OSX/Linux/BSD/Windows with Cygwin

  1. Open a Terminal
  2. Type ssh -p 922 -L 3306:mysql.cs.wwu.edu:3306 username@linux.cs.wwu.edu

Using the Connection

You can now specify your MySQL server as being 127.0.0.1 with port 3306, with whatever you are using to connect to the database.