RuntimeError with mysql2 and rails3 (bundler)

前端 未结 11 2103
花落未央
花落未央 2020-12-12 20:08

I get this error

`establish_connection\': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record         


        
相关标签:
11条回答
  • 2020-12-12 20:41

    as of 0.3.0, and ActiveRecord 3.1 - the ActiveRecord adapter has been pulled out of this gem and into ActiveRecord itself. If you need to use mysql2 with Rails versions < 3.1 make sure and specify gem "mysql2", "~> 0.2.7" in your Gemfile

    the missing file (no such file to load) can be found in the pre 0.3.0 versions of mysql2.

    quoted from the documentation of mysql2

    0 讨论(0)
  • 2020-12-12 20:46

    just run "gem install mysql" also add the same in gemfile and run bundle. worked

    0 讨论(0)
  • 2020-12-12 20:48

    I was getting the same error while using rails 3.0.7 and mysql2 0.3.2. The solution, which I found here, is to use an older version of mysql2. Thus edit your gemfile to

    gem 'mysql2', '< 0.3'
    

    and run

    bundle install 
    
    0 讨论(0)
  • 2020-12-12 20:48

    I'm a beginner at ruby, rails, and linux. So if this solution did not work, I hold no responsibility :)

    Step 1:

    sudo gem uninstall mysql2
    

    Step 2:

    sudo gem install mysql -v 0.2.7
    

    Start webrick, if the same problem still appears reinstall rails.

    This solution works for me.

    0 讨论(0)
  • 2020-12-12 20:50

    Did you include the mysql2 gem in your gemfile instead of the old mysql gem, and ran bundle install afterwards?

    0 讨论(0)
  • If you're using rvm, and possibly added mysql2 outside of rvm, try these steps: Confirm that your Gemfile says:

    gem 'mysql2'
    

    or for Rails2.x:

    gem 'mysql2', '~> 0.2.11'
    

    then:

    $ cd RAILS_ROOT
    $ gem uninstall mysql2
    
    Select gem to uninstall:
     1. mysql2-0.2.11
     2. mysql2-0.3.6
     3. All versions
    > 3 # select "All versions"
    $ rvm gemset install mysql2
    $ bundle install
    

    Now rails should start properly.

    0 讨论(0)
提交回复
热议问题