ruby - net-ssh and ActiveRecord 3: bringing it all together -


i'm working on small ruby program connect remote mysql bugzilla database, perform query of records, , email details of records group on daily basis.

so far, i've been able ssh db server , execute command using net-ssh. here's example:

require 'net/ssh'  net::ssh.start("db.example.com", "sroach", :password => "secret") |ssh| result = ssh.exec!("ls -l") puts result end 

that outputs fine.

using activerecord 3.0.3, wanted test establish_connection method established connection local mysql database , able execute commands using activerecord. example:

require 'active_record'  activerecord::base.establish_connection(     :adapter  => "mysql2",     :host     => "localhost",     :database => "list_tool_development",     :username => "my_username",     :password => "secretpassword" )  class mailinglist < activerecord::base end  mailinglist.first  #=> retrieves first record table 

so, i'm having trouble bringing , applying remote mysql db. here's best try far:

require 'net/ssh'  net::ssh.start("db.example.com", "sroach", :password => "secret") |ssh| ssh.forward.local(3307, "127.0.0.1", 3306) ssh.loop { true } end 

but make irb session hang (which normal...don't know). incase hang was normal, opened new irb session , tried establish connection remote database so:

require 'active_record'  activerecord::base.establish_connection(     :adapter => "mysql2",     :host => "127.0.0.1",     :port => 3307,     :reconnect => false,     :database => "bugs",     :pool => 5,     :username => "my_username",     :password => "secret",     :socket => "/tmp/mysql.sock" )  class bug < activerecord::base  #=> table name in "bugs" db "bugs" end                             #=> made model singular  bug.first  #=> irb session hangs @ point 

so, have no idea what's going wrong or how degub it. , suggestions helpful.

i'm on mac osx. db i'm trying connect on freebsd 7.0 , mysql version ver 14.12 distrib 5.0.67.

rather try tunnel activerecord connection inside ssh, have tried connecting directly activerecord db server? normal way connect across network , directly supported activerecord.

replace host id server host ip or dns entry, port can allowed default mysql driver's default of 3306, , socket isn't needed since db on remote host.

if db host isn't on same network yours, , you're crossing firewalls, might need have port opened allow connection. if on same network should work without needing ssh @ all.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -