Forum: Ruby on Rails Connection to Mysql

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7fe16d11ca75c2de9d29bcc08a85ab9c?d=identicon&s=25 Pedro Cardoso (jotape)
on 2007-02-06 12:10
Hello everyone

I'm developing an aplication in rails, and need to connect to a
diferente database to set up a migration tool, from an old aplication in
php to the new application in rails ;)

So, I need a "low level" con to the old app so I can transfer the data.
And I need to do it in rails to reuse the app already done in rails. Can
someone help ?

6d57db44c5a4e0721cc7f78cf0ce308a?d=identicon&s=25 Stephen Bartholomew (steveb)
on 2007-02-06 12:37
(Received via mailing list)
When I need to do this, I create a script that loads up the rails
environment so I have access to all the application stuff, and then
use a manual database connection.  Let's say we're importing customers
from an old database:

------- /scripts/import_from_old_db.rb
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'mysql'

dbh = Mysql.real_connect("mydatabase", "user", "pass",
old_customers = dbh.query("select * from tblCustomers")

customers = []
while old_customer = old_customers.fetch_hash do
    customers << {:name => customer["Name"], :address =>


There is more information about ruby-mysql here:  You could also use
the rails connection adapters to query the old database - I just
haven't done that yet :0)

Hope that helps,

7fe16d11ca75c2de9d29bcc08a85ab9c?d=identicon&s=25 Pedro Cardoso (jotape)
on 2007-02-06 13:00
Thanks Steve!

I,m going to do a little bit different since I'm going to do a
connection from within the application. I'm going to use mylsq/ruby too.
This topic is locked and can not be replied to.