Recently I had the challenge, that the MySQL database of one of the Magento shops I maintain wasn’t accessible directly through the Net. The access was restricted to the Webserver only. So I had to tunnel MySQL through SSH. And that worked like that:
- edit the ssh config (~/.ssh/config) on the remote Webserver
12Host *ForwardAgent yes
- create a port mapping through ssh (the local port 3307 is mapped to the MySQL standard port of the webserver)
1$> ssh -L 3307:localhost:3306 firstname.lastname@example.org
- Add your key to the server to gain passwordless access to the Webserver
- Now you can use the remote MySQL database in you local Magento installation as if it would be located on the local environment.
123456<host><![CDATA[127.0.0.1]]></host><port><![CDATA]></port><username><![CDATA[username]]></username><password><![CDATA[password]]></password><dbname><![CDATA[database]]></dbname><!-- ... -->
Naturally you can use this port mapping als with other MySQL driven applications or clients.
That’s it. This was how I tunnel MySQL through SSH if required.