The Website of Nicholas Piper [14.08203125]

ssh mysql

This is not the current version of this page!
You may wish to move to the current version.

This page is http://

MySQL over SSH

To use a MySQL client with a server that is the other side of a firewall when you have ssh based access, you can configure ssh so that it creates a tunnel between a port on your localhost and the remote machine's MySQL port (3306 normally).

For example, if the remote machine is called 'kanga' (in my case it was kanga.honeypot.net, but I put kanga as an entry in /etc/hosts) then you run ssh with the argument -L 9999:kanga:3306 kanga like this ;

piamox7:/var/www/new$ ssh -L 9999:kanga:3306 kanga

Now when you connect to 9999 on your machine, you are actually connecting to kanga on port 3306. The data is compressed and encrypted.

The confusing part for me was that all the mysql clients seemed to refuse to use port 9999 to connect via. They always wanted to use the unix socket, hence connecting with MY MySQL server, not kangas.

This is fixed by referring to your machine by its hostname, NOT 'localhost'. For example;

piamox7:/var/www/new$ mysql --host=piamox7 -P 9999 -u nicholas -p

This way, it all works out fine.