Read more

Fix error: Missing the mysql2 gem

Henning Koch
August 07, 2012Software engineer at makandra GmbH

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

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

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

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'
Posted by Henning Koch to makandra dev (2012-08-07 15:47)