Forwarding port 3306 on Mac OS X in order to connect to a remote MySQL Database
Solution 1:
This should work:
ssh -L 3310:127.0.0.1:3306 user@server
The first port number is the local port to use (must not be in use already), the IP in between the colons is the IP to connect to, from the perspective of the host you are sshing into. The second port number is the port to connect to. If you are connecting to a server other than the one you are sshing into, then try the following:
ssh -L 3310:<remote-IP>:3306 user@server
Usually, when I want to do this more than one time, I create an entry in ~/.ssh/config like the following where sshhost.example.com is the server I am sshing to, the local port I want to open is 5910, the IP on the other side I want to connect to is 192.168.35.69, and the port I want to connect to there is 5900:
Host desk
Hostname sshhost.example.com
User jed
Port 22
LocalForward 5910 192.168.35.69:5900
Then from a command prompt I can just do
jed@jed-mbp:~$ ssh desk
and get a tunnel to my desktop at the office.
Good luck,
--jed
Solution 2:
Currently on Mac OS Catalina the -N
argument is needed to avoid a regular login so the updated command would be:
ssh -N -L 5984:127.0.0.1:5984 [email protected]