Gem::LoadError for mysql2 gem, but it's already in Gemfile

Mysoulisinseoul picture Mysoulisinseoul · Apr 8, 2014 · Viewed 51k times · Source
Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded.
Add `gem 'mysql2'` to your Gemfile

This error occurred while loading the following files:

active_record/base

This is the error I get on running rails server.

The mysql2 gem has been added to the Gemfile as well.

I've done bundle install, and tried restarting the server but still get the error.

Answer

Hassan Azimi picture Hassan Azimi · Sep 8, 2015

If you have this error when upgrading to rails 4.2.4 (also with rails 4.1.5) try using this version of mysql2:

gem 'mysql2', '~> 0.3.18'

Apparently mysql2 isn't still compatible with newer version of rails because rails 4.2.4 is pretty new as the time of answering this question by me 8 September 2015 so use the above line in your Gem file and run:

bundle install 

You should be good to go