簡體   English   中英

Ruby gem無法加載-無法加載驅動程序'MySQL'

[英]Ruby gem failure to load - Unable to load driver 'MySQL'

我有一個已運行多年的應用程序。 然后,我們將服務器遷移到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'

程序本身(更改用戶名和密碼)

#!/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), " +...

詳盡的Google搜索發現了有關安裝dbd-mysql的建議,以及其他建議,但沒有一個起作用。

那么,這里失敗了嗎? 我不是Ruby方面的人,我是一個試圖將其備份並運行的低級IT人士。

看起來大小寫敏感的文件系統存在一些問題,在我的Mac上嘗試這樣做,但是我可以通過將連接字符串從“ 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 ~$ 

解決了問題。

核心失敗是Ruby 2.1.0本身的錯誤代碼。 請參閱此處修復Ruby本身。 [ ruby 1.8.7和2.1之間的DBI行/委托行為

一旦開始出現錯誤,我便將Mysql的DBI調用更改為MySQL,希望對其進行修復,但這僅引起了另一個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM