You have MySQL running on your server, but it's opened to local ports for security reasons. If you want to access your databases from something other than webbased apps like PHPMyAdmin, such as the MySQL Query Browser, you'd have to open up access to the outside. That's not very secure, so it's a drawback for using awesome apps like the Query Browser.

Luckily there's a solution. We can use port forwarding through an SSH tunnel. That way, your MySQL client connects to localhost, but it's really connecting to server through the SSH tunnel.

To create the tunnel, you can connect to your server like this:
ssh -L 3306:localhost:3306

The syntax is:
ssh -L <local-port>host-forwarding-to<remote-port> <username>@<remote-host>.

-L for binding the address, the local port, local host, remote port and ssh login data. When you're using apps like MySQL Query Browser, you can connect to localhost, so you can bind the port from there. You can also use ssh -L to forward a port from one server to another.

If you're using MySQL on your local machine as well, you can use a different port to forward to the port on the remote host. When you do this, chances are the tunnel is set up to a privileged port, in which case you need root privileges to access it (that's why sudo is added to the example below). You can point the MySQL Query Browser to the different port, and use a command line like the following:
sudo ssh -L 666:localhost:3306

Once the SSH tunnel is set up, you can fire up the MySQL Query Browser and point it to your host with the port you specified, and you don't even have to open up a port anywhere.

awesome on Thursday 14-06-2012

that is awesome!

React on this article

Enter the code here: