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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)