How to Tunnel a MySQL Connection Through SSH

In a previous post, we highlighted some of the benefits of tunneling with SSH. Now, you will learn how to use an SSH tunnel to connect to MySQL remotely. With this method, you will connect to SSH, forwarding all information on port 3306 (the MySQL port) through this encrypted connection.

To get started, connect via SSH:

ssh -L 3306:localhost:3306 user@yourdomain.tld

Once you have the tunnel open, you can proceed to connect to MySQL as you normally would in order to manage your database. That may involve using MySQL Admin, Query Browser or whatever tool you normally use. Just make sure your connection goes through port 3306, as it should anyway.

This method is great if you want to use a graphical desktop program to manage MySQL (rather than phpMyAdmin or the command line) but do not want to risk having an unsecured connection. SSH can fix all of that for you.

 











Comments: