Gem::LoadError for mysql2 gem, but it's alread

2019-01-10 06:11发布

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.

13条回答
混吃等死
2楼-- · 2019-01-10 06:53

Being Beginner to the ruby i could not figure out the line gem 'mysql2', '~> 0.3.18'

it simply means go to your rails project folder and then there is line for mysql2 it will be like 0.4* so you can change it to gem 'mysql2', '~> 0.3.18'

and as we have new definition, we have to rebuild the dependency so to do that simple command as explained on the top bundle install

查看更多
疯言疯语
3楼-- · 2019-01-10 06:54

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
查看更多
小情绪 Triste *
4楼-- · 2019-01-10 06:56

I'm brand spanking new to Ruby on Rails and websites but hears what worked for me.

I had to change my gemfile, gem 'mysql2' to gem 'mysql2', '~> 0.3.13' then in rails i typed bundle install then i tried rails s and got errors so then i tried bundle update mysql2 then in rails typed rails s, and it worked

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-10 06:57

Change to

gem 'mysql2', '~> 0.3.18'

in your Gemfile.

This thread on the official mysql2 Github says to do this. You need to declare that version number if you're rails version 4.x.x.

https://github.com/brianmario/mysql2/issues/675

Then run bundle update mysql2.

查看更多
Root(大扎)
6楼-- · 2019-01-10 06:57

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
查看更多
等我变得足够好
7楼-- · 2019-01-10 07:00

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.

查看更多
登录 后发表回答