I'm attempting to establish a tunnel to a remote server via ssh, and then use the forwarded port to access MySQL.
I'm using it currently like this
$gateway = Net::SSH::Gateway.new('target.server', 'user')
def with_gateway
$gateway.open("target.server", 3306) do |port|
yield port
end
end
Which in my mind would be similar to this...
`ssh -L #{port}:localhost:3306 -N user@target.server`
Then when I try to use it and do something like this.
with_gateway do |port|
puts `mysql -u user -ppass -h 127.0.0.1 -P #{port} -e SHOW\ DATABASES\;`
end
It gives me this error message..
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
What am I missing?