MySQL and SSH Tunneling for an improved quality of life

August 4th, 2009

Lately I have had several projects where I need to get to a MySQL database behind a firewall on another server. In some cases I could access the database via phpMyAdmins web interface, which is useful but hardly a great user experience, in other cases it was command line access to the database only. Instead I want to use my standard MySQL GUI which means that I need to set up a SSH tunnel to the remote host. After reading way to much about SSH tunneling and trying way to many suggested commands that turned out not to work for whatever reason I finally got it right, and it has improved my quality of life immensely (OK, that might be to exaggerate just a little bit). Maybe everybody else already have figured this out, but by blogging about it at least I know that I can find my own instructions again when needed…

I run OSX 10.5 and use Sequel Pro as my MySQL GUI, but if you use something else the approach should be similar. I assume that you do have SSH access to the remote server and also access rights to the database.

  • Open a terminal window and run the command “ssh -NC <username>@<remote server> -L 3307:127.0.0.1:3306″
    • <username> is your username on the remote server
    • <remote server> is the IP address or URI to the remote server you want to connect to
  • You will be asked for the password for, write it in an leave the terminal window open. You now have a SSH tunnel to the remote server that is using port 3306 on the remote server and mapping it to your local port 3307.
  • Open Sequel Pro and connect to your remote servers database using host “127.0.0.1″ and port “3307″ and the username/password used on the remote database.
  • Time to do whatever you want to do in the database from within Sequel Pro (much much nicer than phpMyAdmin)

Don’t you feel a bit happier already?

Popularity: 3% [?]

2 Responses

  1. Matt Langtree says:

    Tuesday, August 4th, 2009at 3:32

    Hi Andreas,

    Thanks for your support for Sequel Pro.

    At the time of writing we have just pushed out a release candidate of Sequel Pro 0.9.6 which features SSH Tunnelling built right in.

    http://www.sequelpro.com/blog/

    Kind Regards,

    Matt Langtree
    Sequel Pro Developer

  2. Andreas says:

    Tuesday, August 4th, 2009at 5:49

    Thanks for the comment Matt, downloading the new Sequel Pro right now. I really had the perfect timing on this post ;)

andreas krohn

About me

My name is Andreas Krohn and I work with mashups, web scraping and other similar technologies to create web applications that have a higher value for the end user than the sum of the parts. I live in Helsingborg, Sweden but work internationally.

More about me, my services, my projects & how to contact me.

twitter
    follow me on Twitter