如何正确安装Ruby的DBI gem,以便它可以与MySql对话? [英] How do I get Ruby's DBI gem properly installed so that it can talk to MySql?
本文介绍了如何正确安装Ruby的DBI gem,以便它可以与MySql对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Windows 7上,我已经安装了Ruby 1.9.2,并安装了以下gem:
On my Windows 7 box, I've installed Ruby 1.9.2, and installed the following gems:
*本地宝石*
- dbd-mysql(0.4.4)
- dbi(0.4.5)
- 已弃用(2.0.1)
- httparty(0.8.1)
- rubygems-update(1.8.15)
- dbd-mysql (0.4.4)
- dbi (0.4.5)
- deprecated (2.0.1)
- httparty (0.8.1)
- rubygems-update (1.8.15)
(我使用gem install做到了)。
(I did this using gem install).
我也编写了以下简单的测试工具:
I have also written the following simple test harness:
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
断开连接关于如何指定连接字符串的说明,我不断得到:
Regardless of how I specify the connection string, I keep getting:
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>'
}
我在做什么错了?
推荐答案
找到了在此问题。
在64位操作系统上运行Ruby时,需要将新版本的libMySql.dll复制到Ruby\bin目录中。该dll的最佳来源是此处。
When you are running Ruby on a 64 bit operating system, you need to copy a new version of libMySql.dll into the Ruby\bin directory. The best source for that dll is here.
这篇关于如何正确安装Ruby的DBI gem,以便它可以与MySql对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文