3

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 user@remote.com -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 user@remote.com -T -N -L 6603:remote.com:3306 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?

Peter
  • 822
  • 2
  • 10
  • 23

2 Answers2

2

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

 mysql -P 6603 -u user -p
Stone
  • 7,011
  • 1
  • 21
  • 33
  • 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 08:29
  • 2
    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 127.0.0.1 as I did in the past. Archive logs saved my day. – Peter Feb 20 '12 at 09: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 08 '15 at 04:06
0

try: ssh -L6603:localhost:3306 ssh user@remote.com

aka, forward all traffic to localhost port 6603 to remove.com 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.

InChargeOfIT
  • 408
  • 3
  • 5