I'm using SqlYog and PUTTY in order to connect to a MySQL server sitting on a remote server. I'm able to the MySQL server sitting on the host I connect to through PUTTY, but the thing is I use PUTTY to make my way into a different server using two more SSH's in PUTTY. How do I connect to the third SSH's host's MySQL server??? I'm using for the primary SSH this tunneling: 3306: And I connect to 3306 on localhost on SqlYog...

migrated from stackoverflow.com Jun 19 '11 at 18:08

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

  • 1
    Leapfrogging SSH is not programming - superuser or serverfault... – OMG Ponies Jun 19 '11 at 17:45
  • I don't understand this part: "I use PUTTY to make my way into a different server using two more SSH's in PUTTY." Are you saying that you ssh into one server, and then to the next, and finally to the 3rd where the MySQL server is running? – Kirk Jun 19 '11 at 19:36
  • Yes this is exactly what i'm doing. I cannot SSH to the third server directly.. – user86585 Jun 19 '11 at 20:06

So you appear to have four machines. Workstation (your starting point), and then serverA, serverB and serverC. You can SSH to serverA only. From there, you can only get to serverB and you have MySQL running on serverC. From workstation, you want to connect directly to MySQl on serverC?

Let's take this in steps. If you were running MySQL on serverB, and wanted to connect to it from workstation via serverA you would use this, from workstation.

ssh -L eitan@serverA.example.net

That opens a connection to serverA from your workstation. On your workstation it listens on port 3306 and sends stuff it finds over the tunnel. The tunnel is actually to serverA but when it arrives, it shoves it to the destination which is serverB (port 3306).

You have an extra hop, so you need to put a new tunnel in first.

Connect to serverA via ssh as normal, and create a tunnel straight through to MySQL on serverC using,

ssh -L eitan@serverB.example.net

Now, create the first part of the tunnel from your workstation,

ssh -L eitan@serverA.example.net

Traffic sent to your workstation port 3306 is now routed all the way to serverC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy