1
votes

I'm trying to run a rails app. Everything is pretty basic. My gemfile is

gem 'rails', '4.0.0'

gem 'mysql2'

database.yml is

development: adapter: mysql2

encoding: utf8

database: #new_app_development

pool: 5

username: root

password: password

host: localhost

gem list gives mysql2 (0.4.0)

but still I'm getting Gem::LoadError Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile.

I tried both bundle install and gem install mysql2.

3
Maybe you need this: [gemload error][1] [1]: stackoverflow.com/questions/32457657/…Štefan Bartoš

3 Answers

1
votes

It doesn't load mysql2 gem because new version of mysql2(0.4.1) gem unable to load the mysql2_adaptor. This is working for me.

gem 'mysql2', '~> 0.3.13'

and run

bundle install

If still facing problem then This solution will surely help

Note: I'm assuming that you've mysql database installed on your system :P

1
votes
 gem 'mysql2', '~> 0.3.20'

ERROR: While executing gem ... (Gem::CommandLineError)

Unknown command mysql2,

but

gem install mysql2 

Building native extensions. This could take a while...

Successfully installed mysql2-0.4.1

1 gem installed

and then bundle install, but this combination not working

0
votes

It was caused by mysql2 just upgraded to 0.4.0 on Sep 8th(see here) and it has something compatibility issue with current rails version. Because by default, rails doesn't specify the version for mysql2 in the Gemfile, so once you issue command bundle, rails will always install the latest mysql2 from remote, which is 0.4.0 in this case.

Forturnly, rails official has addressed this issue and they will support mysql2 0.4.0 from next rails 4.2(see here)

And obviously, the solution is to downgrade the mysql2 by spesifying its version to 0.3.x in the Gemfile, like this:

gem 'mysql2', '~> 0.3.20'

And then, issue command bundle.