【问题标题】:Unable to connect mysql from Sequel gem无法从 Sequel gem 连接 mysql
【发布时间】:2009-07-17 17:15:07
【问题描述】:

当我尝试从 Sequel 连接到 MySQL 时。我收到这些错误:

require 'rubygems'
        require 'sequel'
        DB = Sequel.connect(:adapter => 'mysql', :user => 'root', :host => 'localhost', :database => 'scanty',:password=>'xx')
        DB.tables
    Sequel::DatabaseConnectionError: NameError uninitialized constant Mysql::CLIENT_MULTI_RESULTS
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/adapters/mysql.rb:98:in `connect'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/database.rb:92:in `initialize'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:166:in `call'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:166:in `make_new'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:153:in `available'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:144:in `acquire'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:143:in `synchronize'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:143:in `acquire'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/connection_pool.rb:105:in `hold'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/database.rb:471:in `synchronize'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/adapters/mysql.rb:128:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/dataset.rb:314:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/adapters/mysql.rb:342:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/adapters/mysql.rb:298:in `fetch_rows'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/dataset.rb:185:in `each'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/dataset/convenience.rb:156:in `map'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/dataset/convenience.rb:156:in `map'
        from /opt/local/lib/ruby/gems/1.8/gems/sequel-3.2.0/lib/sequel/adapters/shared/mysql.rb:60:in `tables'
        from (irb):6irb(main):007:0> Sequel::DatabaseConnectionError: NameErro

【问题讨论】:

  • 您的错误似乎被截断了?另外,你的函数调用中的主机在哪里?
  • 我添加了主机,但它仍然抛出同样的错误

标签: mysql ruby sequel


【解决方案1】:

需要安装原生的MySQL驱动,纯ruby的驱动不兼容Sequel。

根据您的 Ruby 安装,只需执行 gem install mysql 可能就足够了。但是,如果纯 Ruby mysql.rb 文件已经在您的 Ruby 加载路径中,您要么需要将其从加载路径中删除,要么在调用 Sequel.connect 之前使用 gem('mysql')

【讨论】:

    【解决方案2】:

    您缺少:host=>'localhost' 或任何您的主机。

    另外,这纯粹是出于性能原因,您应该尝试启用:compress。它可以节省大量带宽。

    http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html

    编辑:好的,如果不是主机,可能是冲突?见http://groups.google.com/group/sequel-talk/browse_thread/thread/ee39640a92351f1?pli=1。还有http://www.mail-archive.com/sequel-talk@googlegroups.com/msg02275.html

    【讨论】:

    • 谢谢,我在机器上安装了两个版本的 mysql gem。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-26
    • 2013-11-21
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    相关资源
    最近更新 更多