我有一个已经运行多年的应用程序。然后,我们将服务器迁移到Ubuntu 15.04并安装了Ruby。
sudo apt-get install curl
sudo apt-get install ruby2.1
sudo gem update --system
sudo apt-get install rake
apt-get install ruby-dev
sudo gem install amatch
sudo apt-get install libmysqlclient-dev
sudo gem install -r dbi
sudo gem install -r mysql dbd-mysql
然后我们运行程序并得到这个错误..
/var/lib/gems/2.1.0/gems/dbi-0.4.5/lib/dbi.rb:300:in `block in load_driver': Unable to load driver 'MySQL' (underlying error: uninitialized constant DBI::DBD::MySQL) (DBI::InterfaceError)
from /usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /var/lib/gems/2.1.0/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
from /var/lib/gems/2.1.0/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
from /var/lib/gems/2.1.0/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
程序本身(用户名和pw已更改)
#!/usr/bin/ruby
require "rubygems"
gem 'mysql'
gem 'dbi'
require "dbi"
require "amatch"
include Amatch
name_sub = { "unit" => "un",
"unt" => "un",
"tract" => "tr",
"estate" => "est",
"university" => "univ",
"trust" => "trst" }
op_sub = { "partnership" => "PS",
"partnershp" => "PS",
"partner" => "PS",
"prtnr" => "PS",
"ptnr" => "PS",
"ptnrsp" => "PS",
"corporation" => "C",
"corp" => "C",
"company" => "co",
"incorporation" => "I",
"inc" => "I",
"oil" => "O",
"gas" => "G",
"exploration" => "E",
"production" => "P",
"operating" => "oper",
"energy" => "engy",
"management" => "mgmt",
"resources" => "res",
"minerals" => "min",
"petroleum" => "pet" }
def mangle(s, dictionary = {})
return "" unless s
# lowercase | special case | alphanumerics only
s.downcase().gsub(/l.l.c./, 'llc').gsub(/\W/, " ").split(" ").map do |word|
dictionary.fetch(word, word)
end.join(' ')
end
stop_attempts = -1
PRODUCTION = false
begin
# now the actual code
# development database
DBI.connect("dbi:MySQL:database=matching;" "host=enus", "mott", "bM^7ezOqYyn") do |outdb|
DBI.connect("dbi:MySQL:database=ownership;" "host=enus", "mott", "bM^7ezOqYyn") do |lease_db|
# re-create phase3 table
outdb.do("drop table if exists phase3")
sql = "create table phase3 (" +
"id bigint not null auto_increment primary key, " +
"lod_id bigint, rrc_id bigint, district varchar(255), " +
"name_percent float, rrc_lease_no varchar(255)," +
"op_percent float, field_percent float, total float, " +
"key k1 (lod_id), key k2 (rrc_id), key k3 (district), " +...
详尽的谷歌搜索找到了安装dbd-mysql的建议,以及其他建议但没有奏效。
那么这里失败了什么?我不是一个红宝石的家伙,我是一个狡猾的IT人,试图让它恢复正常运行。
答案 0 :(得分:1)
看起来在这里尝试使用区分大小写的文件系统存在一些问题,但我可以通过将连接字符串从“MySQL更改为”Mysql“来获得测试工作,例如:
2.1.5@test_dbi ~$ cat test_dbi.rb
#!/usr/bin/ruby
require "rubygems"
require 'dbi'
DBI.connect("dbi:Mysql:database=matching;" "host=enus", "mott", "bM^7ezOqYyn")
2.1.5@test_dbi ~$
答案 1 :(得分:0)
解决了这个问题。
核心故障是Ruby 2.1.0本身的错误代码。 看到这里修复Ruby本身。 [DBI Row / delegate behavior between ruby 1.8.7 and 2.1
一旦我开始收到错误,我将Mysql的DBI调用更改为MySQL希望修复它,但这只会引起另一个问题。