Fix error: Missing the mysql2 gem

Posted Almost 12 years ago. Visible to the public.

So you got this error, even though your Gemfile bundles mysql2:

!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'

or

Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.)

The reason for this confusing error message is probably that your Gemfile says mysql2, but your database.yml still uses the mysql adapter. Change it to use the mysql2 adapter:

development:
  adapter: mysql2
  database: myproject_development
  encoding: utf8
  username: root
  password: secret

Note if you're on an old Rails version

If you're using a Rails version less than 3.1 (e.g. 2.3.x, 3.1.x), you need the mysql2 in a 0.2.x version. Newer versions no longer include the ActiveRecord adapter (which is part of ActiveRecord since Rails .1). So your Gemfile should say:

gem 'mysql2', '~0.2.0'
Henning Koch
Last edit
About 11 years ago
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-08-07 13:47)