Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError with mysql2 and rails3 (bundler)

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.

like image 714
Swistak Avatar asked Aug 12 '10 11:08

Swistak


4 Answers

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 
like image 65
stream7 Avatar answered Oct 14 '22 10:10

stream7


Also need to change adapter from mysql to mysql2 in database.yml as said here Install mysql2 gem on Snow Leopard for Rails 3 with rvm

From:

development: adapter: mysql

To:

development: adapter: mysql2

like image 45
vrybas Avatar answered Oct 14 '22 08:10

vrybas


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

like image 14
amaseuk Avatar answered Oct 14 '22 10:10

amaseuk


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.

like image 6
mmell Avatar answered Oct 14 '22 09:10

mmell