Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to do an ssh tunnel to connect to a mysql server. if i do :

me@local> mysql -h host -u user -p pwd

I get a 100 error

I have an ssh account on a distant server and this command works :

me@ssh-server> mysql -h host -u user -p pwd

I would like to create a ssh tunnel but i cannot figure out the propper command. Anybody got an idea ?

share|improve this question

migrated from Nov 1 '10 at 11:43

This question came from our site for professional and enthusiast programmers.

Use the -L parameter for SSH to create a tunnel and redirect port 3306 (MySQL's port).

ssh -f me@ssh-server -L 3306:ssh-server:3306 -N

Then simply connect locally as you would on ssh-server. If you're on Windows locally, the parameters are pretty much the same for plink.

share|improve this answer
If MySQL is running on the ssh machine, change "ssh-server" to "localhost" if it fails to connect. If MySQL is running on another host, use that other host's name in place of "ssh-server" in the -L option on the ssh command. Then when connecting to the MySQL server from the local machine, use "-h localhost". on the mysql command. – Skaperen Nov 9 '12 at 1:51

You better read more for port forwarding and SSH. read this or eventually a topic that I made recently might be useful for you If you have further question reply to my answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.