cool, it works fine . so appreciated.
On Tuesday, 23 August 2016 21:49:11 UTC+8, Jeremy Evans wrote:
>
> On Tuesday, August 23, 2016 at 6:42:07 AM UTC-7, Tim Sheng wrote:
>>
>> #!/usr/bin/env ruby
>> require 'rubygems'
>> require 'mysql'
>> require 'net/ssh/gateway'
>> require 'sequel'
>>
>>
>> HOST = '54.222.195.145'
>> SSH_USER = 'admin'
>> DB_HOST = "stage-mysql-27.cdendvrkytps.rds.cn-north-1.amazonaws.com.cn"
>>
>>
>>
>>
>> gateway = Net::SSH::Gateway.new(HOST, SSH_USER, :keys => [
>> "~/.ssh/infra_stage-id_rsa" ],)
>> port = gateway.open(DB_HOST,3306,3306)
>>
>>
>> child = fork do
>> db = Sequel.connect(:adapter => 'mysql', :host => '127.0.0.1',:port
>> => port, :user => 'root', :password => 'tMq2OhtrF3afh1FL', :database =>
>> 'wechat_db')
>> puts db['select id from lead'].count
>> end
>> puts "child: #{child}"
>> Process.wait
>> gateway.close(port)
>>
>>
>>
>> I can set up a connection with mysql using the code above , and print the
>> number of `lead` table records.
>> when i use the following code directly
>> db = Sequel.connect(:adapter => 'mysql', :host => '127.0.0.1',:port
>> => port, :user => 'root', :password => 'tMq2OhtrF3afh1FL', :database =>
>> 'wechat_db')
>> puts db['select id from lead'].count
>>
>>
>> the program is hanging up.
>>
>> is there a way to connect remote mysql using sequel via ssh without fork
>> a child process, because i want to retrieve `db` object, so i can continue
>> to do it using this object,
>> but now the fork block only seems to return a `child` process number.
>>
>> i can realise the same feature with mysql2, but the api for sequel seems
>> to be more elegant. i want to use sequel gem.
>>
>>
>> require 'rubygems'
>> require 'mysql2'
>> require 'net/ssh/gateway'
>>
>>
>> ssh_gate = Net::SSH::Gateway.new(
>> '54.222.195.145',
>> 'admin',
>> :keys => [ "~/.ssh/infra_stage-id_rsa" ],
>> )
>>
>>
>> puts 'true' if ssh_gate.active?
>>
>>
>> ssh_gate.open('
>> stage-mysql-27.cdendvrkytps.rds.cn-north-1.amazonaws.com.cn', 3306, 3306)
>>
>>
>> client = Mysql2::Client.new(
>> host: "127.0.0.1",
>> username: 'root',
>> password: 'tMq2OhtrF3afh1FL',
>> database: 'wechat_db',
>> port: 3306
>> )
>> results = client.query("SELECT * FROM lead")
>> results.each do |row|
>> p row
>> end
>> client.close
>>
>>
>> Thanks
>> Tim
>>
>
> My first thought would be to change from :adapter=>'mysql' to
> :adapter=>'mysql2' in the Sequel code. Hopefully that by itself should fix
> things.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.