Handling Rails 4 Mysql2 Gem LoadError

“Upgraded to Rails 4 and getting the Mysql2 Gem LoadError?”

Last night I was asked to maintain a Rails 3 web project. My first suggestion was to upgrade from Rails 3.2 to 4.x. I went through a Rails updating guide and when I tried to launch the rails server I was getting this error:

Rails 4 - Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded

I ended up finding that the issue is not with mysql2 gem or with MySQL compatibility but with the ActiveRecord adapter.

To resolve this issue I just had to specify the mysql2 gem to a version like ‘~> 0.3.18’ or ‘~> 0.3.20’

Changing the line your Gemfile: gem ‘mysql2’ to gem ‘mysql2’, ‘~> 0.3.18’ will resolve the error.

Here is the exact code snippet for copying:

gem "mysql2", "~> 0.3.18"

You can read more about the issue that was reported on Rails Github repository here.

Discussions — No responses yet