To connect to MySQL through a tunnel
Open a tunnel on your local machine listening on localhost:3307 and forwarding everything to the mysqlserver server on port 3306, and doing it all via the ssh service on the gateway machine.
ssh -L 3307:domain.name.of.mysqlserver:3306 username@domain.name.of.gatewayserver
Now start mysql connecting to localhost on the port that you are tunneling mysql from the mysql server.
mysql -u username -p -h 127.0.0.1 -P 3307 databasename
mysql assumes it’s connecting to localhost, but on a non-standard port. In fact, the connection is being made securely to the remote mysql server, via the gateway machine and the local “mouth” of the ssh tunnel on your own machine.
—————————————————
tunnel all outbound E-mail traffic back to my personal server to avoid having to change SMTP servers when I am behind firewalls.
ssh -f user@personal-server.com -L 2000:personal-server.com:25 -N
—————————————————-
to send my Google Talk traffic encrypted through the firewall back to my server at home and then out to Google.
ssh -f -L 3000:talk.google.com:5222 home -N
—————————————————