Cannot connect to remote db using ssh tunnel and activerecord

后端 未结 2 1577
小鲜肉
小鲜肉 2020-12-24 11:08

I\'m having some trouble with the following script:

require \'rubygems\'
require \'active_record\'
require \'net/ssh/gateway\'

gateway = Net::SSH::Gateway.n         


        
2条回答
  •  执念已碎
    2020-12-24 11:45

    I was able to get this to work without a fork by using the mysql2 gem

    require 'rubygems'
    require 'active_record'
    require 'mysql2'
    require 'net/ssh/gateway'
    
    gateway = Net::SSH::Gateway.new(
      'remotehost.com',
      'username'
    )
    port = gateway.open('127.0.0.1', 3306, 3307)
    
    class Company < ActiveRecord::Base
      establish_connection(
        :adapter  => "mysql2",
        :host     => "127.0.0.1",
        :username => "dbuser",
        :password => "dbpass",
        :database => "dbname",
        :port     => 3307
      )
    end
    puts Company.all.size
    

提交回复
热议问题