Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 stackoverflow.com Nov 1 '10 at 11:43

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

2 Answers 2

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 http://www.debianadmin.com/howto-use-ssh-local-and-remote-port-forwarding.html or eventually a topic that I made recently might be useful for you http://stackoverflow.com/questions/3969264/noob-questions-for-svn-checkout-and-network-issues-regading-it. If you have further question reply to my answer.

share|improve this answer

Your Answer

 
discard

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.