How do I configure Rails for password-less access to remote database

前端 未结 2 1303
情话喂你
情话喂你 2020-12-30 06:55

Note: this is similar to Use Ruby on Rails and SSH to access remote MySQL database on remote server, but the OP didn\'t provide much info, and the only answer given does

2条回答
  •  悲哀的现实
    2020-12-30 07:37

    First, you need to establish an SSH tunnel the MySQL server. On the client machine, run:

    ssh -fNg -L 3307:127.0.0.1:3306 guardian@salt.woofwoof.com
    

    That will establish an SSH tunnel to the salt.woofwoof.com server. Any connections to localhost port 3307 will get sent through the tunnel to the remote host on port 3306.

    Then just configure your database.yml like you would for a local connection, but specify the forwarded port 3307:

    canine:
      adapater: mysql2
      database: canine
      username: bowser
      password: *secret*
      port: 3307
    

    You may also want to add the ssh tunnel setup to /etc/inittab so that the tunnel is establish after boot. See http://chxo.com/be2/20040511_5667.html for one example of how to do that.

提交回复
热议问题