This document describes how to set up an SSH tunnel to use with MacSQL. This resolves an issue
with users failing to connect to 3rd party database hosts that do not allow remote connections
to their database server.
Complete the following steps to connect to a database server via an SSH tunnel:
- Open the Terminal application (located in /Applications/Utilities).
- At the command line enter the following:
$ ssh -L port1:127.0.0.1:port2 username@remotehost.com
Where port1 is the port you wish to open on your machine (any number between 1025 and 64000)
and port2 is the port on the remote server for the database. For example MySQL's default
port is 3306. If you are not running a database server on your local machine you can use
the same number for both ports.
- If prompted, enter the password associated with the username you used to connect to
the ssh server.
- Leave this Terminal window open until you are finished with the database connection you will open below.
- Open MacSQL and select "New..." from the File menu. Choose the database type you wish to connect to.
- In the Host box, enter: 127.0.0.1
- In the Port box, enter the port number you entered for port1.
- Enter the database userid and password.
- Press the Connect button.
This will open a connection to the remote server via the ssh tunnel you have open in Terminal.
Your service provider will see you connected to the database via their ssh server as
if you were using a command-line tool.