Forum: Ruby Problem in accessing MySQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fd47c9a969dacb631be2dfe4f0d1273c?d=identicon&s=25 Bhaskar Ms (bhaskar)
on 2009-05-27 11:16
Hi,
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'
   begin
     # connect to the MySQL server
     dbh=DBI.connect("DBI:Mysql:<db-name>:<remote-Host>", "user",
"password")

     # 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}"
   ensure
     # disconnect from server
     dbh.disconnect if dbh
   end


Here is the error:
>ruby simple.rb
c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:294:in
`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
`load_driver'
  from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:154:in
`_get_full_driver'
  from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:139:in
`connect'
  from simple.rb:10
>Exit code: 1
This topic is locked and can not be replied to.