2

I'm trying to get to a mysql server on a remote network, and to get to it I currently have to do several ssh hops, so I can use the mysql command line interface. I'd really like to do a mulit-hop tunnel so I can just use a gui from my desktop. How would this work?

Here's the order:

MacDesktop --> DevServer -->StageServer --> Mysql01

All (except the mac desktop)are linux boxes, and mysql is running on the standard port. Any Hints? Or an exact connection string?

  • Hrm. Seems like that didn't work. Not sure what I'm doing wrong, but I'm essentially putting: (in Terminal one) dev.xyz.com>: ssh -L 3306:user@Mysql01.xyz.com:3306 @userStage.xyz.com (in Terminal two (on my mac)) ssh -L 3306:127.0.0.1:3306 user@dev.xyz.com It looks like the dev server is running mysql on it.. so am I going to need to forward a different port? If so, how? edit: I'tried port 3307, but when I did a netstat -an | grep 3307 on any of the hosts, it never showed up. :-/ –  Sep 20 '11 at 19:03

2 Answers2

4

You can use ssh to forward the ports(assuming that the mysql server is configured to accept connections from StageServer on port 3306):

# Forward port 3306 from Mysql01 to local port 3306 on DevServer using StageServer in the middle
DevServer > ssh -L 3306:Mysql01:3306 StageServer
# Forward the local port 3306 on DevServer to local port 3306 on your Mac
MacDesktop> ssh -L 3306:127.0.0.1:3306 DevServer

Now configure the gui client to connect to 127.0.0.1:3306 (Make sure you're not running mysql on your Mac or forwarding to port 3306 will fail, or use another port for forwarding)

Edit: Make sure that local port forwarding is enabled in ssh server configuration.

1

I know this question is old, but this is still very useful.

Use a multiline command to create a chained tunnel, like this:

ssh -f <DevServer> "ssh -f -L 5678:<MySQL01>:3306 <StageServer> \"sleep 10\"";\
ssh -f -L 3306:127.0.0.1:5678 <DevServer> "sleep 10";\
mysqlsh --sql -h127.0.0.1 -P3306 -u<UserName> -D<Schema>

This connects the MySQL client utility to the remote DB, and then when you exit, both of the tunnels are closed. The tunnel in this case runs through port 5678, but you can use any unused port number.