Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3874524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:09:41+00:00 2026-05-19T22:09:41+00:00

I’m working on a small Ruby program that will connect to a remote MySQL

  • 0

I’m working on a small Ruby program that will connect to a remote MySQL Bugzilla database, perform a query of records, and email details of those records to a group on a daily basis.

So far, I’ve been able to SSH to the db server and execute a command using net-ssh. Here’s an example:

require 'net/ssh'

Net::SSH.start("db.example.com", "sroach", :password => "secret") do |ssh|
result = ssh.exec!("ls -l")
puts result
end

That outputs just fine.

Using ActiveRecord 3.0.3, I wanted to test the establish_connection method so I established a connection to my local MySQL database and was able to 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  #=> Successfully retrieves first record from the table

So, where I’m having trouble is bringing it all together and applying it to my remote MySQL db. Here’s my best try thus far:

require 'net/ssh'

Net::SSH.start("db.example.com", "sroach", :password => "secret") do |ssh|
ssh.forward.local(3307, "127.0.0.1", 3306)
ssh.loop { true }
end

But all that does is make my IRB session hang (which could be completely normal…don’t know). Incase that hang was normal, I opened a new IRB session and tried to establish a connection to the remote database like 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  #=> the table name in the "bugs" db is "bugs"
end                             #=> so I made the model singular

Bug.first  #=> the IRB session hangs at this point

So, I have no idea what’s going wrong or how to degub it. Any and all suggestions would be helpful.

I’m on Mac OSX. The db that I’m trying to connect to is on FreeBSD 7.0 and is MySQL version Ver 14.12 Distrib 5.0.67.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:09:42+00:00Added an answer on May 19, 2026 at 10:09 pm

    Rather than try to tunnel the ActiveRecord connection inside SSH, have you tried connecting directly from ActiveRecord to the DB server? That is the normal way to connect across a network and is directly supported by ActiveRecord.

    Replace the host ID with the server host IP or DNS entry, the port can probably be allowed to default to the MySQL driver’s default of 3306, and the socket isn’t needed since the DB is on the remote host.

    If the DB host isn’t on the same network as yours, and you’re crossing firewalls, you might need to have that port opened to allow the connection. If it is on the same network it should work without needing ssh at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.