Gem::LoadError
Specified \'mysql2\' for database adapter, but the gem is not loaded.
Add `gem \'mysql2\'` to your Gemfile
This error occurred while
I had the same error and this is because Rails 4.1 requires minimum mysql2 version 0.3.13, and maximum compatible with Windows is version 0.3.11.
So I edited file c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\activerecord-4.1.1\lib\active_record\connection_adapters\mysql2_adapter.rb
and changed line gem 'mysql2', '~> 0.3.13'
to gem 'mysql2', '~> 0.3.11'
, and it works so far.
This issue may occur if you're using newer version of rails > 4
Do these two simple steps, it will work. Open your Gemfile and find the below line
gem 'mysql2'
replace that line with a specific mysql version like below
gem 'mysql2', '~> 0.3.18'
Now stop the server and run bundle
bundle install
Now restart your server. It should work.
rails s
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
I got the same error after an upgrade to Rails 4.1 and I managed to resolve it by updating mysql2. Run this in your rails app folder:
$ bundle update mysql2
It worked for me when I specified a mysql2 gem version before the newest one (0.4.0). For some reason there is a problem with Rails 4.2.4 and that gem 0.4.0. So, to solve the problem I just specified the previous gem released: 0.3.20 and it worked fine for me!
gem 'mysql2', '~> 0.3.20'
bundle install
You can check all the gems versions here: https://rubygems.org/gems/mysql2/versions
It doesn't load mysql2 gem because new version of mysql2 (>= 0.4.0) gem unable to load the mysql2_adaptor. Can you try this?
gem 'mysql2', '~> 0.3.13'
Hopefully, it should work.