How To Connect to a remote mysql server using mysqlcc and ssh tunneling.

1 minute read

This will explain how to connect to a remote mysql server only allowing connections from locahost, from your computer in a secure way as it is being done through a ssh tunnel.

What we are going to do here is to create a tunnel from your localhost to your remote host (the one the sql and ssh servers are running on).

If your sql server and ssh server runs on different machines, please read on and then refer to How To: Connect to a remote mysql server using mysqlcc and ssh tunneling part 2

This tunnel allow you to have a secure connection from your computer to the remote host.

First of all, we are going to configure ssh. Edit or Create file ~/.ssh/config. Add the following lines (depending on your settings):

Host myhostnickname
User mysshuser Localforward 3307 localhost:3306
#only if using rsa or dsa key authentification
IdentityFile ~/.ssh/myremotehost_id_dsa

connect to your remote host

$ ssh myhostnickname

This way, when you connect to your remote host via ssh, you create a tunnel which allow you to communicate from your local computer port 3307 to the remote machine on port 3306. For the remote host, it is like you were communicating on localhost port 3306.

In mysqlcc, create a new connection (Ctrl+N). Give it the name you like to describe it, set hostname to (not localhost… it seems mysqlcc can’t recognize localhost as, set username to your remote username, same with password. As we have created a tunnel from port 3307 to 3306, mysqlcc is going to connect on port 3307 so set port to 3307.

You are done, you can now connect to a remote mysql server accepting only local connections from your computer and all this in a secure way.