Use Ruby on Rails and SSH to access remote MySQL d

2019-07-29 07:29发布

问题:

How do I use SSH to make my RoR db calls to a remote MySQL db on a remote server. I have the host ip, ssh username, ssh password, db, db username, db password, and port. Any examples I have seen show the code just in a ruby script but I do not know how to apply that solution to my web application. Do I need to change anything in my database.yml file? I appreciate any help...

回答1:

The way to go about this is to create an SSH Tunnel to the destination database host and point the local server to it. Check out: How do I configure Rails for password-less access to remote database



回答2:

You can connect to remote databases from Rails. Simply edit your database.yml:

development: 
  adapter: mysql
  encoding: unicode
  pool: 5
  username: username
  password: password
  host: hostname
  port: port_number
  database: database_name