Rails mysql2 error: "rake aborted! Please install the mysql2 adapter ..."

I run this on a machine with Windows 7 (64 bit). I installed RoR with a one-click installer. I updated the database.yml file to use mysql2:

development: adapter: mysql2 encoding: utf8 database: blog_development pool: 5 username: root password: socket: /tmp/mysql.sock test: adapter: mysql2 encoding: utf8 database: blog_test pool: 5 username: root password: socket: /tmp/mysql.sock production: adapter: mysql2 encoding: utf8 database: blog_production pool: 5 username: root password: socket: /tmp/mysql.sock 

I added this line to my Gemfile (for the training video):

 gem 'mysql2', :group => :production 

Then:

 gem install mysql2 

which succeeds. Then:

 bundle install 

This also succeeds, but mysql2 is not specified.

Then:

 rake db:create 

which gives this error:

"rake aborted! Install the mysql2 adapter: gem install activerecord-mysql2-adapter (my sql2 is not part of the package. Add it to the Gemfile.) Tasks: TOP => db: create (See Complete trace by completing the task with --trace ) "

 bundle show mysql2 

Gives this error: "Could not find gem" mysql2 "in the current package."

What am I missing to get mysql2?

+4
source share
3 answers

Run bundle install before rake db:create (after gem install mysql2 )

+1
source

Go to your app

  • Open gemfile
  • Add this line

    gem 'mysql2'

+2
source

A similar problem was resolved for me after

  • creating the libmysql.lib file for https://github.com/brianmario/mysql2/issues/486 and using it to install / compile native stones (lib located in the directory used for "- -with-mysql-lib =" $ mysql top_path / lib "" gem installation)
  • install libmysql.dll in the biny_top bin folder
  • installation of both mysql and mysql2 gems (the exact same error was obtained as when installing only mysql2 gem, although database.yml is everywhere "adapter = mysql2").

After mysql2 appeared in the list of stones after the command "bundle install", I was able to successfully run "rake db: create", launched redmine x64 windows on x64 ruby ​​2.0 from x64 mysql on webrick, continuing to configure on some production server.

================

Update

I need to clarify that in addition to installing both mysql and mysql2, I created a Gemfile.local file in the top redmine application directory, which probably did the trick with bundler. Therefore, I would recommend replacing the last step:

  • install mysql2 gem
  • creating a Gemfile.local file in the top folder of the application, where you list the local gems that will be included in your kit.

I saw another answer that recommends adding mysql2 gem to the Gemfile, but for me mysql2 was already included in the Gemfile, but appeared in the bundler release after adding only to Gemfile.local.

I leave both solutions, if I am mistaken, and the trick was performed using the mysql gem installed with mysql2, unfortunately I can not remove / reinstall everything from scratch now to check it for sure, I will update when I am able to do this, I hope that all this will save someone time.

The contents of my Gemfile.local file:

--- & 8 l; ---

gem "mysql2", "~> 0.3.11"

gem "eventmachine"

gemstone "thin"

--- & 8 l; ---

+1
source

Source: https://habr.com/ru/post/1402285/


All Articles