Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

User mysql2 taked uninitialized constant Mysql error.

#5432

hsli@hs-li:~/work/homeland$ rake db:create --trace
(in /home/hsli/work/homeland) Invoke db:create (first_time) Invoke db:load_config (first_time) Invoke rails_env (first_time) Execute rails_env Execute db:load_config Execute db:create rake aborted!
uninitialized constant Mysql
/home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0.rc2/lib/active_record/railties/databases.rake:68:in rescue in rescue in create_database' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0.rc2/lib/active_record/railties/databases.rake:64:inrescue in create_database' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0.rc2/lib/active_record/railties/databases.rake:39:in create_database' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0.rc2/lib/active_record/railties/databases.rake:33:inblock (2 levels) in ' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in call' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:inblock in execute' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in each' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:inexecute' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in block in invoke_with_call_chain' /home/hsli/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:inmon_synchronize' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:ininvoke' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:inblock (2 levels) in top_level' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in each' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:inblock in top_level' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:intop_level' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in block in run' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in run' /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in' /home/hsli/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in load' /home/hsli/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in'



I was checked the /home/hsli/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0.rc2/lib/active_record/railties/databases.rake file line 68, is use Mysql::Error trouble is here, I've try add gem "mysql" into Gemfile, the error was not happen.
new result show me database config was not correct.

Reported by huacnlee (at gmail) · August 24th, 2010 @ 07:46 AM

State: resolved
Milestone: 3.0.2
Assigned to: Andrew White Andrew White
Importance: High

Activity

  1. huacnlee (at gmail)
    huacnlee (at gmail)

    This is Rails3 Rc2 my database.yml:

    development:
    adapter: mysql encoding: utf8 reconnect: false database: homeland_development pool: 5 username: monster password: 123123 host: 172.28.150.23

    August 24th, 2010 @ 08:10 AM

  2. huacnlee (at gmail)
    huacnlee (at gmail)

    last is wrong, I use mysql2 not mysql

    development:
    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: homeland_development
    pool: 5
    username: monster
    password: 123123
    host: 172.28.150.23

    August 24th, 2010 @ 08:12 AM

  3. Andrew White
    Andrew White
    • Importance changed from to Low

    You need to have mysql2 in your Gemfile not mysql - works fine for me in a new app.

    August 24th, 2010 @ 08:39 AM

  4. huacnlee (at gmail)
    huacnlee (at gmail)

    I was installed mysql2! and I found the resolvtion.
    when I change database.yml to:
    development:
    adapter: mysql2 encoding: utf8 reconnect: false database: "homeland_development" pool: 5 username: "monster" password: "123123" host: "172.28.150.23"

    add quotes to string value, but why?

    August 24th, 2010 @ 08:46 AM

  5. Andrew White
    Andrew White
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to Andrew White
    • Importance changed from Low to High

    The problem is that YAML is treating your password as a integer and the Mysql2 library generates an exception when passed a Fixnum for the password. The db:create task assumes that mysql is available and tries to rescue the error but the error class is Mysql2::Error not Mysql::Error so you get the undefined constant error.

    The attached patch fixes the db:create task and I've raised an issue on http://github.com/brianmario/mysql2

    August 24th, 2010 @ 12:49 PM

  6. Repository
  7. Repository
  8. The_Lord
    The_Lord

    It certainly works with database adapter set to mysql2, but still fails when using em_mysql2 (also provided with the mysql2 gem).

    August 25th, 2010 @ 07:40 PM

  9. The_Lord
    The_Lord

    Allright it works now with rails 3.0 final release.

    August 31st, 2010 @ 02:53 AM

  10. Jeremy Kemper
  11. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:54 AM