Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its v

I am getting this error while I am trying to run my ruby project with mysql or mysql2. I have the gem file at the right place and yet it is giving this error. I have installed and reinstalled everyting more than 2 time, but this error wont go.

Can anyone help please.

1 Answer

Patrick Metcalfe
PLUS
Patrick Metcalfe
Courses Plus Student 7,563 Points

Hi, so mysql recently updated to version 0.4.0. Rails depends on the version being 0.3.x even though rails new project generates an unbound dependency—which would resolve to the latest version (0.4.0).

Rails has patched it and provided a back port but that version hasn't been released yet. So whenever they release the new version the issue will go away.

There are a few things you could do.

  1. Go into you gems file and add a version constraint to mysql2 like so: gem "mysql2", "~> 0.3.0" # Note the last .0 that's essential
  2. Use rails master. This isn't a great options for a million reasons and is probably unnecessary for you but technically you could do this.

(See https://github.com/rails/rails/issues/21544)