在我的Windows 7盒子上,我安装了Ruby 1.9.2,并安装了以下gem:
*本地宝石*
(我是使用gem install完成的。)
我还写了以下简单的测试工具:
require 'rubygems'
require 'dbi'
begin
dbh = DBI.connect("DBI:Mysql:test", "username", "pwd")
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
无论我如何指定连接字符串,我都会得到:
C:\Code\Concordance.SE>ruby test_sql.rb
C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:300:in `block in
load_driver': Unable to load driver 'Mysql' (underlying error: uninitialized con
stant DBI::DBD::Mysql) (DBI::InterfaceError)
from C:/Tools/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
from C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:242:
in `load_driver'
from C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:160:
in `_get_full_driver'
from C:/Tools/Ruby192/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:145:
in `connect'
from test_sql.rb:4:in `<main>'
}
我做错了什么?