Jan-Erik R.
2/16/2009 4:25:00 PM
Brian Candler schrieb:
> Ad Ad wrote:
>> the box on which mysql is staged accepts connections only from
>> localhost. I couldn't get mysql to connect directly using the mysql gem.
>
> Sounds like ssh tunneling is what you want.
>
> To demonstrate using the command-line ssh, type the following on the
> 'client' host:
>
> ssh -L12345:127.0.0.1:3306 remote.host.com
>
> While this ssh session is open, point any Mysql client (such as the Ruby
> mysql client) at localhost:12345, and the connection will be redirected
> down the ssh tunnel and connect to the mysql server at the other end.
> The connection at the other end will originate from the ssh daemon, so
> is "local" as far as the mysql server is concerned.
>
> The advantage of this approach is you have full native SQL access,
> rather than having to mess around with sending command lines, and so
> higher layers will run on top of this too (like ActiveRecord)
>
> Once you have this working to your satisfaction, you may wish to improve
> this by using Net::SSH to set up the tunnel from within Ruby as well.
> I've not done this, but I believe it's possible. Read the docs, and ask
> if you can't work it out.
another method could be to install the mysql-gem on the remote server
and then execute a ruby script via the ssh.exec method in your local
script =D