Posted By

caspyin on 03/29/12


Tagged

textmate ssh+remote


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ab1


Remote+Query+Over+SSH+Tunnel


 / Published in: Other
 

  1. gateway = Net::SSH::Gateway.new(
  2. 'remotehost.com',
  3. 'username'
  4. )
  5. port = gateway.open('127.0.0.1', 3306, 3307)
  6.  
  7. # use cmd line to verify connection over ssh tunnel
  8. # mysql -u root -p -h 127.0.0.1 --port 3307
  9.  
  10. client = Mysql2::Client.new(
  11. host: "127.0.0.1",
  12. username: 'root',
  13. password: '',
  14. database: 'dbname',
  15. port: port
  16. )
  17. results = client.query("SELECT * FROM projects")
  18. results.each do |row|
  19. p row
  20. end
  21. client.close
  22.  

Report this snippet  

You need to login to post a comment.