Tunnel MySQL through SSH

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
  • create  a port mapping through ssh (the local port 3307 is mapped to the MySQL standard port of the webserver)
  • 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.

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.