Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a very strange problem with SSH Tunnel. I want to connect to a remote MySQL Server using an SSH Tunnel. I have created the tunnel with great success in the past, but for a strange reason it's not OK now. The Tunnel is created as: ssh -T -N -L 6603:localhost:3306.

When I try to connect to the remote MySQL Server, the connection is performed on the local MySQL server!

So, I tried to use the ssh -T -N -L which is not what all how-tos say, but what the man page do.

No success :( Everything that I have tried is not working and now I am really confused. What is wrong with that setup?

share|improve this question
How are you connecting to mysql? –  Roy Feb 20 '12 at 7:45

2 Answers 2

try: ssh -L6603:localhost:3306 ssh

aka, forward all traffic to localhost port 6603 to port 3306

You would then use host: 'localhost' and port 6603 to connect to server.

You can also check to make sure that the local port is not in use (netstat -tnlp for example) and that 3306 is not being blocked by a firewall.

share|improve this answer

Are you connecting to the server with the -P command line option? Like:

 mysql -P 6603 -u user -p
share|improve this answer
Of course. And to be sure that I don't use the local socket, I use the --protocol tcp option too. –  Peter Feb 20 '12 at 8:29
OK, I found it. The problem is that I used the "localhost" which by default it connects to your mysql server though the UNIX socket. So, I should use as I did in the past. Archive logs saved my day. –  Peter Feb 20 '12 at 9:11
Peter, thanks for posting your solution. I was just preparing to ask the same question here, and voila! I tried your suggestion and it worked like a charm. Now if I could just get back the lost hour I wasted, trying to solve it myself... –  joe May 8 at 4:06

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.