This project is archived and is in readonly mode.

#5502 ✓resolved
rdinca

rake db:create problem in rails3 with mysql2

Reported by rdinca | August 30th, 2010 @ 08:44 PM | in 3.0.2

Here is the trace of the error

rake db:create --trace
(in /home/radu/projects/r30) 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! undefined method errno' for #<Mysql2::Error:0xb70e1ebc> /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:71:increate_database' /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:33 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:inexecute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:insynchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:ininvoke' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:inload' /usr/bin/rake:19


I addressed the problem to the mysql2 gem creators on github and they told me it is rails3 related:

This is actually a bug in the Rails 3 database rake tasks at: http://github.com/rails/rails/blob/master/activerecord/lib/active_r...

Mysql2::Error has a method called error_number whereas the old mysql gem's error class has errno - this should be an easy fix but would you mind opening a bug in the Rails 3 tracker?

Comments and changes to this ticket

  • Neeraj Singh

    Neeraj Singh August 30th, 2010 @ 09:11 PM

    • State changed from “new” to “open”
    • Tag set to rails 3, activerecord
    • Importance changed from “” to “Low”

    Attached is a code patch. Can you try and see if it fixes your problem.

  • Marjan Krekoten'

    Marjan Krekoten' August 30th, 2010 @ 10:48 PM

    I have another patch which addresses this issue and also nonexistent Mysql::Error#error method. It also deals with situation when we use old mysql gem and 'uninitialized constant Mysql2' message gets raised.

  • rdinca

    rdinca August 31st, 2010 @ 04:14 PM

    I can confirm Marjan Krekoten' s patch is working for me ( haven't tried the other one ), but it is rather unpleasant having to modifing database.rake... perhaps the patch should be included into rails right away, not forcing mysql users to hack into activerecord files.

  • Marjan Krekoten'

    Marjan Krekoten' September 1st, 2010 @ 07:02 AM

    • Assigned user set to “José Valim”
  • José Valim

    José Valim September 1st, 2010 @ 08:26 AM

    • Milestone cleared.
    • Assigned user changed from “José Valim” to “Brian Lopez”
    • Importance changed from “Low” to “Medium”

    Brian, do you think we can make MySQL2 error have the same API as MySQL one and do a small release?

  • Marjan Krekoten'

    Marjan Krekoten' September 1st, 2010 @ 09:00 AM

    I agree with José Valim. It probably would be better to do somthing like this

    class Mysql2::Error
        # ...
        alias_method :errno, :error_number
        alias_method :error, :message
    end
    

    But following is still needed, because it avoids 'uninitialized constant Mysql2' when we use mysql instead of mysql2:

    error_class = "#{config['adapter'].capitalize}::Error".constantize
    

    I can edit this patch and also make patch for mysql2 if José Valim and Brian Lopez agree with this.

  • Brian Lopez
  • Marjan Krekoten'

    Marjan Krekoten' September 1st, 2010 @ 08:06 PM

    Cool! I've updated patch to fix 'uninitialized constant Mysql2'. But this problem will go away completely with new release of mysql2 gem.

  • Brian Lopez

    Brian Lopez September 1st, 2010 @ 08:07 PM

    I'll try and push 0.2.4 by tonight

  • jw

    jw September 2nd, 2010 @ 04:58 PM

    Is there a non hacky way for a rails mortal like me to resolve this problem? I have updated to rails 3 today and have since not been able to do any development. Thanks.

  • Bison

    Bison September 8th, 2010 @ 08:00 PM

    Any progress on this issue? I'm new to Rails and (like jw) this has held me up for almost a week now. Is there an easy workaround? Thanks.

  • Marjan Krekoten'

    Marjan Krekoten' September 8th, 2010 @ 09:29 PM

    Well we need to wait for next release of mysql2. It will introduce compatibility with mysql gem. Or you can point your Gemfile to mysql2 git repo.

  • Marjan Krekoten'

    Marjan Krekoten' September 19th, 2010 @ 09:03 PM

    mysql2 v0.2.4 released with mysql compatibility fix. So I think we should update development and generated Gemfile to use >= 0.2.4. I've attached a patch.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:02 PM

    • Milestone set to 3.0.2
  • Ryan Bigg

    Ryan Bigg October 16th, 2010 @ 02:38 AM

    • Tag changed from rails 3, sheepskin boots, activerecord to activerecord rails 3

    Automatic cleanup of spam.

  • Rohit Arondekar

    Rohit Arondekar October 25th, 2010 @ 09:43 AM

    Currently the Gemfile uses 0.2.6. The rest hasn't been applied yet. Was the issue resolved?

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 1st, 2010 @ 05:06 PM

    • Tag cleared.

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino November 11th, 2010 @ 03:45 AM

    • State changed from “open” to “resolved”

    I have talked with Brian and this is resolved now. If somebody has still some kind of trouble with this, please comment here and I will reopen it.

  • John

    John December 12th, 2010 @ 05:30 PM

    Hi, I'm running rails 3.0.3, ruby 1.9.2p0, mysql 5.1.53, and when i run rake db:create I get the following:

    ** 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
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.1/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in `rescue in create_database'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:39:in `create_database'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33:in `block (2 levels) in <top (required)>'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
    /Users/John/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'
    

    My gems are:

    *** LOCAL GEMS ***
    
    abstract (1.0.0)
    actionmailer (3.0.3, 3.0.0)
    actionpack (3.0.3, 3.0.0)
    activemodel (3.0.3, 3.0.0)
    activerecord (3.0.3, 3.0.0)
    activeresource (3.0.3, 3.0.0)
    activesupport (3.0.3, 3.0.0)
    addressable (2.2.2)
    arel (2.0.6, 1.0.1)
    bcrypt-ruby (2.1.2)
    builder (2.1.2)
    bundler (1.0.2)
    cgi_multipart_eof_fix (2.5.0)
    configuration (1.2.0, 1.1.0)
    cucumber (0.10.0, 0.9.3)
    cucumber-rails (0.3.2)
    daemons (1.1.0, 1.0.10)
    database_cleaner (0.6.0)
    devise (1.1.5, 1.1.3)
    diff-lcs (1.1.2)
    erubis (2.6.6)
    faraday (0.5.3)
    fastthread (1.0.7)
    gem_plugin (0.2.3)
    gherkin (2.3.2, 2.2.9)
    i18n (0.5.0, 0.4.1)
    jasmine (1.0.1.1, 1.0.1)
    json (1.4.6)
    json_pure (1.4.6)
    launchy (0.3.7)
    mail (2.2.12, 2.2.7)
    mime-types (1.16)
    mongrel (1.2.0.pre2)
    multi_json (0.0.5)
    multipart-post (1.0.1)
    mysql2 (0.2.6)
    net-ldap (0.1.1)
    nokogiri (1.4.4, 1.4.3.1)
    oa-basic (0.1.6)
    oa-core (0.1.6)
    oa-enterprise (0.1.6)
    oa-oauth (0.1.6)
    oa-openid (0.1.6)
    oauth (0.4.4)
    oauth2 (0.1.0)
    omniauth (0.1.6)
    pg (0.9.0)
    polyglot (0.3.1)
    pyu-ruby-sasl (0.0.3.2)
    rack (1.2.1)
    rack-mount (0.6.13)
    rack-openid (1.2.0)
    rack-test (0.5.6)
    rails (3.0.3, 3.0.0)
    railties (3.0.3, 3.0.0)
    rake (0.8.7)
    rest-client (1.6.1)
    rspec (2.0.1)
    rspec-core (2.0.1)
    rspec-expectations (2.0.1)
    rspec-mocks (2.0.1)
    rspec-rails (2.0.1)
    ruby-openid (2.1.8)
    ruby-openid-apps-discovery (1.2.0)
    rubyntlm (0.1.1)
    selenium-client (1.2.18)
    selenium-rc (2.2.4)
    spork (0.8.4)
    term-ansicolor (1.0.5)
    thor (0.14.6, 0.14.3)
    treetop (1.4.9, 1.4.8)
    tzinfo (0.3.23)
    warden (1.0.2, 0.10.7)
    webrat (0.7.2)
    
  • mehstg

    mehstg December 29th, 2010 @ 12:57 PM

    I am having the same issue. Any ideas guys?

    root@localhost:/var/ruby/testapp# rake db:create --trace
    (in /var/ruby/testapp) 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 Mysql2
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in create_database' /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in load' /usr/bin/rake:19

  • mehstg

    mehstg December 29th, 2010 @ 01:05 PM

    Hi guys

    I am having the same issue at the moment. I am running Rails 3.0.3

    Local Gems:

     LOCAL GEMS 


    abstract (1.0.0) actionmailer (3.0.3) actionpack (3.0.3) activemodel (3.0.3) activerecord (3.0.3) activeresource (3.0.3) activesupport (3.0.3) arel (2.0.6) builder (2.1.2) bundler (1.0.7) columnize (0.3.2) erubis (2.6.6) i18n (0.5.0) linecache (0.43) mail (2.2.13) mime-types (1.16) mysql (2.8.1) mysql2 (0.2.6) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.3) railties (3.0.3) rake (0.8.7) ruby-debug (0.10.4) ruby-debug-base (0.10.4) ruby-debug-ide (0.4.16) sqlite3-ruby (1.3.2) SystemTimer (1.2.1) thor (0.14.6) treetop (1.4.9) tzinfo (0.3.23)

    Database config:

    development:
      adapter: mysql2
      encoding: utf8
      database: testapp_development
      pool: 5
      username: root
      password: tax1Rank
      socket: /tmp/mysql.sock

    Warning: The database defined as "test" will be erased and

    
    
    

    re-generated from your development database when you run "rake".

    
    
    

    Do not set this db to the same as development or production.

    
    
    
    test: adapter: mysql2 encoding: utf8 database: testapp_test pool: 5 username: root password: tax1Rank socket: /tmp/mysql.sock
    production: adapter: mysql2 encoding: utf8 database: testapp_production pool: 5 username: root password: tax1Rank socket: /tmp/mysql.sock

    Rake with trace:

    (in /var/ruby/testapp)
     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 Mysql2
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in create_database'
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain'
    /usr/lib/ruby/1.8/monitor.rb:242:in synchronize'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
    /usr/bin/rake:19:in load'
    /usr/bin/rake:19</code>
    </pre>
    
  • Marjan Krekoten'
  • Goksel

    Goksel January 18th, 2011 @ 01:35 AM

    • Assigned user cleared.

    It seems like a Mysql Version Problem. Try uninstalling MYSQL 5.5 if you have this version and install MYSQL 5.1

  • Goksel

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages