Forum: Ruby Problem in accessing 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.
Bhaskar M. (Guest)
on 2009-05-27 13:16
I'm new to ruby and facing the following problem in connecting to MySQL
from my script.

Here is the script:
#!/usr/bin/ruby -w
   #~ # simple.rb - simple MySQL script using Ruby DBI module
  gem "mysql"
gem "dbi"
require "dbi"
#~ gem 'dbd-mysql'
     # connect to the MySQL server
     dbh=DBI.connect("DBI:Mysql:<db-name>:<remote-Host>", "user",

     # get server version string and display it
     row = dbh.select_one("SELECT VERSION()")
     puts "Server version: " + row[0]
   rescue DBI::DatabaseError => e
     puts "An error occurred"
     puts "Error code: #{e.err}"
     puts "Error message: #{e.errstr}"
     # disconnect from server
     dbh.disconnect if dbh

Here is the error:
>ruby simple.rb
`load_driver': Unable to load driver 'Mysql' (underlying error:
uninitialized constant DBI::DBD::Mysql) (DBI::InterfaceError)
  from c:/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
  from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:236:in
  from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:154:in
  from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:139:in
  from simple.rb:10
>Exit code: 1
This topic is locked and can not be replied to.