Brain Dump

A place to store my random thoughts and anything else I might find useful.

Access MySQL with mysql-query-browser over ssh tunnel

Posted by mzanfardino on October 23, 2008

Problem:
Your mysql database lives on a server that has all but a handful of ports blocked. Specifically you can’t use mysql-query-broswer to connect directly as port 3306 is blocked.

Solution:
Tunnel traffic through an ssh connection and forward the traffic from some other port (assuming you have mysql running on your localhost on port 3306) to port 3306.

How?

Simple: Open a new shell and create the tunnel on the local machine to the remote server as follows:

ssh -L $localport:127.0.0.1:3306 -l $remoteuserid $remoteserveraddress

  • $localport can be any available port, include 3306, but only if mysql is *not* running on the local machine.
  • $remoteuserid is the user id used to connect to the remote server.
  • $remoteserveraddress is the address of the remote server.

Once the tunnel is established, leave the shell open. You might get timed out depending on your server configuration, so you might need to have some application running on the remote server to maintain the connection.

Now launch mysql-query-browser, set the Server Hostname to 127.0.0.1 and the port to $localport. That’s it!

Advertisements

One Response to “Access MySQL with mysql-query-browser over ssh tunnel”

  1. Diego said

    Thanks for the info!
    Diego from Argentina

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: