Unable to connect mysql from Sequel gem
Asked Answered
D

2

8

When I try to connect to MySQL from Sequel. I am getting these errors:

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
Disagreement answered 17/7, 2009 at 17:15 Comment(2)
Seems that your error is truncated? Also, where is the host in your function call?Allness
i added host but it still throwing same errorDisagreement
A
14

You need to install the native MySQL driver, the pure ruby one is not compatible with Sequel.

Depending on your Ruby installation, just doing gem install mysql may be enough. However, if the pure Ruby mysql.rb file is already in your Ruby load path, you either need to remove it from the load path or use gem('mysql') before calling Sequel.connect.

Aversion answered 4/8, 2009 at 21:55 Comment(0)
A
1

You are missing the :host=>'localhost' or whatever your host is.

Also, and this is just purely for performance reasons, you should try to enable :compress. It can save a TON of bandwidth.

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

Edit: OK, if it's not the host, perhaps it's a conflict? See http://groups.google.com/group/sequel-talk/browse_thread/thread/ee39640a92351f1?pli=1. Also http://www.mail-archive.com/[email protected]/msg02275.html

Allness answered 17/7, 2009 at 17:31 Comment(1)
thanks, I have two versions of mysql gem installed on machine.Disagreement

© 2022 - 2024 — McMap. All rights reserved.