1
我試圖通過ssh建立隧道到遠程服務器,然後使用轉發端口訪問MySQL。使用net/SSH /網關建立SSH隧道到MySQL
我使用它目前喜歡這個
$gateway = Net::SSH::Gateway.new('target.server', 'user')
def with_gateway
$gateway.open("target.server", 3306) do |port|
yield port
end
end
這在我的腦海裏與此類似...
`ssh -L #{port}:localhost:3306 -N [email protected]`
然後,當我嘗試使用它,做像這樣的東西。
with_gateway do |port|
puts `mysql -u user -ppass -h 127.0.0.1 -P #{port} -e SHOW\ DATABASES\;`
end
它給了我這個錯誤的短信..
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
我缺少什麼?