Skip to content

Instantly share code, notes, and snippets.

@Shaglock
Last active June 14, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shaglock/2104a13e4d9a74015e1fa9356e9ee9f7 to your computer and use it in GitHub Desktop.
Save Shaglock/2104a13e4d9a74015e1fa9356e9ee9f7 to your computer and use it in GitHub Desktop.
require 'net/ssh/gateway'
require 'active_record'
# there is no password here as the local user `user` has an SSH key stored on the remote server
gateway = Net::SSH::Gateway.new('domain.tld', 'user')
port = gateway.open('127.0.0.1', 3306, 3307)
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
host: '127.0.0.1',
username: 'dbuser',
password: 'dbpassword',
database: 'dbname',
port: port
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment