Return to Snippet

Revision: 56456
at March 29, 2012 05:41 by caspyin


Initial Code
gateway = Net::SSH::Gateway.new(
  'remotehost.com',
  'username'
)
port = gateway.open('127.0.0.1', 3306, 3307)

# use cmd line to verify connection over ssh tunnel
# mysql -u root -p -h 127.0.0.1 --port 3307

client = Mysql2::Client.new(
  host: "127.0.0.1",
  username: 'root',
  password: '',
  database: 'dbname',
  port: port
)
results = client.query("SELECT * FROM projects")
results.each do |row|
  p row
end
client.close

Initial URL

                                

Initial Description

                                

Initial Title
Remote+Query+Over+SSH+Tunnel

Initial Tags
textmate

Initial Language
Other