Connect to remote MySQL server via SSH tunnel

To connect to remote MySQL server via SSH tunnel run commands:

# ssh -L 3307:1.2.3.4:3306 taras@1.2.3.4

Where 3307 local port, 1.2.3.4 remote MySQL server IP, 3306 remote MySQL port, taras – valid SSH user name.

To check if tunnel connection has been set up:

# lsof -i :3307

Connect to remove MySQL server using local SSH tunnel:

# mysql --port 3307 -h 127.0.0.1 -u db_user -p db_name