RuntimeError with mysql2 and rails3 (bundler)

MysqlRuby on-RailsBundler

Mysql Problem Overview


I get this error

`establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
  from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-

Here is dump of whole error and my config and gemfile.

Mysql Solutions


Solution 1 - Mysql

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 

Solution 2 - Mysql

Also need to change adapter from mysql to mysql2 in database.yml as said here https://stackoverflow.com/questions/4297253/install-mysql2-gem-on-snow-leopard-for-rails-3-with-rvm

From:

development:
  adapter: mysql

To:

development:
  adapter: mysql2

Solution 3 - Mysql

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

Solution 4 - Mysql

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.

Solution 5 - Mysql

This also fixed the issue I had with:

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)

You actually need to run: gem install mysql2 and add the gem to your config.

Solution 6 - Mysql

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

Solution 7 - Mysql

If anybody still facing problem of installing mysql2 gem with rails 3 on Windows, then refer to the detailed steps of installation on -

http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

Solution 8 - Mysql

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.

Solution 9 - Mysql

Same issue for me too. Upgraded to Rails 3.1.rc4 then downgraded to 3.0.3. Worked for me.

Solution 10 - Mysql

> 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

Solution 11 - Mysql

I had the same error after upgrading from Ubuntu 11.10 to 12.04. This is how I fixed the problem:

gem uninstall mysql2
bundle

I think the key here is the 'native extensions' -- I suppose when I installed last, I was using a different version of mysql.

Installing mysql2 (0.3.11) with native extensions

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSwistakView Question on Stackoverflow
Solution 1 - Mysqlstream7View Answer on Stackoverflow
Solution 2 - MysqlvrybasView Answer on Stackoverflow
Solution 3 - MysqlamaseukView Answer on Stackoverflow
Solution 4 - MysqlmmellView Answer on Stackoverflow
Solution 5 - MysqlmaxkaplanView Answer on Stackoverflow
Solution 6 - MysqlsupriyaView Answer on Stackoverflow
Solution 7 - MysqlRitesh KumarView Answer on Stackoverflow
Solution 8 - MysqlTimView Answer on Stackoverflow
Solution 9 - MysqlconnieView Answer on Stackoverflow
Solution 10 - MysqlRafael PereaView Answer on Stackoverflow
Solution 11 - MysqlJosh W LewisView Answer on Stackoverflow