Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.

@s56258

#エラー解消 RailsでMySQL bundle install エラー

RailsでMySQLを使ってみた時に出たエラー

DBの指定はrails new時点で、DBをデフォルトのSQLiteからMySQLに指定することが可能ですがしていなかったので、
途中からDBをMySQLに指定しようとしたら出たエラーです。

したこと

Gemfileに gem 'mysql2'と記述し、bundle installをした。

エラー

bundle install後にエラー

エラーメッセージ
Gem files will remain installed in
/Users/*ユーザー名*/*ペアレントディレクトリ名*/*カレントディレクトリ名*/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2 for inspection.
Results logged to
/Users/*ユーザー名*/*ペアレントディレクトリ名*/*カレントディレクトリ名*/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

解決コマンド

bundle config --local build.mysql2 --with-opt-lib=/usr/local/opt/openssl/lib --with-opt-include=-I/usr/local/opt/openssl/include
bundle config build.mysql2 --with-opt-lib=/usr/local/opt/openssl/lib --with-opt-include=-I/usr/local/opt/openssl/include

2つともしてください。

もう一回

Gemfileにgem 'mysql2'と記述し、bundle install --path vendor/bundle

メッセージ

Installing mysql2 0.5.2 with native extensions
Bundle complete! 19 Gemfile dependencies, 79 gems now installed.
Gems in the group production were not installed.
Bundled gems are installed into `./vendor/bundle`

解決〜!!
Qiita記事の方に感謝。

参考にした記事

1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What is going on with this article?