Posted By


caspyin on 03/29/12

Tagged


Statistics


Viewed 702 times
Favorited by 1 user(s)

Remote+Query+Over+SSH+Tunnel


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.