Please install mysql adapter 'gem install activerecord-mysql-adapter'

别来无恙 提交于 2019-11-30 04:41:34

The problem is on your file config/database.yml

You should have a line that specify that the adapter is mysql2 (and not mysql)

adapter: mysql2

Instead of

adapter: mysql

What helped for me was specifying adapter mysql2 instead of mysql (note the digit!) in config/database.yml.

1) You need to update your config/database.yml file and change:

adapter: mysql

into

adapter: mysql2

2) You need to update your Gemfile and explicitly add activerecord-mysql2-adapter dependency there:

gem 'mysql2'
gem 'activerecord-mysql2-adapter'
Aaron Henderson

I never would have believed it but deleting my database.yml file and recreating it actually solved the problem for me too. Thanks Tyler. I spent hours installing and uninstalling different versions of the gems mysql, mysql2, activerecord-mysql-adapter, etc... In the end, my gemfile has

gem 'mysql2', "~>0.3.11"

and my database.yml file has

adapter: mysql2

I am on OSX 10.8, rails 3.2.8, and ruby 1.9.3.

By the way, I experienced the same issues with the mysql2 adapter on my Windows 7 machine. Uninstalling and even deleting the directory for the activerecord-mysql-adapter gem seemed to be critical as well.

You want to install the mysql2 gem.

Really, you should probably add it to your Gemfile:

gem "mysql2"

And then install your gems with bundler:

bundle install
user2822413

This might be late but bundle install was installing 0.4.0 So I tried to edit the gem file and I replace mysql2 with

gem 'mysql2', "~>0.3.11"

and then

bundle install

in the terminal (This will install mysql2 0.3.11 and not the last version) I think active record have problems working with the last version. Well I hope it helps

parag

Step 1. gem 'mysql2', "~>0.3.11" instead of gem 'mysql2' in Gemfile

Step 2. putting mysqllib.dll (available at mysql installation C:\wamp\bin\mysql\mysql5.5.24\lib ) in the C:\ruby2.0.0\bin folder solved the rake db:migrate problem and successfully connected my rails with mysql (database.yml contains mysql2)

I'm running windows 7, 64bit, mysql 64bit, ruby 2.0.0 [x64-mingw32]

Thanks you all for your inputs.

I had the same problem as OP on OSX Lion after upgrading to Rails 3.2. Removing all gems, bundle install, etc did not work. Gemfile and database.yml were correctly specifying mysql2.

In the end, I deleted and recreated my database.yml and everything works again. It was probably a typo or hidden character in the file.

If nothing helps (you have mysql2 as adapter in your database.yml) and you are using RVM to manage your ruby versions, here is the simplest solution:

Try to remove all of your old gemsets (including global), install a fresh ruby version and bundle again. I could solve the problem that way.

Medhat Gayed

It is possible that you have changed adapter to mysql2 for a certain environment only but are not passing the environment to the rake command.

E.g. I only changed mysql to mysql2 on the production environment but was running

rake generate_secret_token

when I changed it to the following it worked:

rake generate_secret_token RAILS_ENV=production

you have mentioned your database.yaml file already has mysql2.

Its worth checking if you have activerecord-mysql2-adapter installed. (Note -mysql2- )

I would say that change the commented information on top in database.yml to

# 
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

second: add " gem 'mysql2' " (what ever is inside the double quotation marks) to gemfile .

save everything, do bundle install. Hope that helps.

or it just could be a typo.

Haris Khalique

I am facing the same issue and getting same error when run command

gem install activerecord-mysql2-adapter

you need to install libmysqlclient-dev

sudo apt-get install libmysqlclient-dev

It works for me

biolinh

In my case, when I also got this error:

rake aborted! Please install the mysql adapter: gem install activerecord-mysql-adapter (mysql is not part of the bundle. Add it to Gemfile.)

After I searched Google and tried many ways, it didn't work. Finally, the answer is

  • Navigate to the root of your app, run open gemfile
  • Add the line gem 'mysql2', '< 0.3.7' directly below the gem line for rails.

For a old rails 2.3.18 ruby 1.8.7 app that I 'migrated' to a new MacBook (High Sierra - 10.13.6), in order to get the app to run (using POW) and to use script/console, I had to disable SIP and create a link to a file in /urs/lib/ directory. Migration Assistant was unable to create the link because of SIP.

To Disable SIP - System Integrity Protection

  1. Boot into Mac OS Recovery Mode as usual by holding down the Command and R keys during system start.

  2. Choose the language as usual (if applicable)

  3. At the “MacOS Utilities” screen, pull down the “Utilities” menu from the top of the screen.

  4. In terminal, type command: csrutil disable

  5. Restart your computer

Finally, after restarting, in Terminal enter this command:

sudo ln /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

I just added the following line to my Gemfile an it worked:

gem "mysql"

Before:

source 'https://rubygems.org'

gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...

After:

source 'https://rubygems.org'

gem "mysql"
gem "rails", "3.2.16"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
...
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!