For security reasons, many hosting providers restrict external access to the default MySQL port 3306. But if you have SSH access to the database server, you can access the MySQL server from your local machine by using an SSH tunnel. An SSH tunnel forwards bits back & forth between a port on your machine and a port on the remote machine, all lovingly encrypted with SSH.
Here's how you do it! But first, my assumptions:
- You already have configured SSH access to the remote server.
- You want to access port 3306 on the remote server.
- You want to access port 3307 on your local machine. This is simply because many devs (myself included) routinely have MySQL running on port 3307.
Here is the Unix command to open an SSH tunnel to hostname_or_ip
with the user account username