0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MYSQL と RAILSの接続が上手くいかなかった

Posted at

#問題点

Rails db:createが上手くいかなかった。

$ bundle exec rails db:create

すると、以下のエラ〜メッセージが。

rails aborted!
LoadError: dlopen(/Users/naganoyuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/mysql@5.6/lib/libmysqlclient.18.dylib
  Referenced from: /Users/naganoyuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/naganoyuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
/Users/naganoyuki/Desktop/VTQ2/config/application.rb:7:in `<main>'
/Users/naganoyuki/Desktop/VTQ2/Rakefile:4:in `<main>'
/Users/naganoyuki/Desktop/VTQ2/bin/rails:9:in `<top (required)>'
/Users/naganoyuki/Desktop/VTQ2/bin/spring:15:in `require'
/Users/naganoyuki/Desktop/VTQ2/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)

rails sも上手くいかなかった。
bundle installも上手くいかなかった

#解決法

以下のコマンドで、一旦bundle installができるようになった。
(効果があったのかどうかは微妙)

$ brew switch openssl 1.0.2s

以下のコマンドでrails sと rails db:create (rails db:migrate)もできるようになった。

$ brew info openssl
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
$ bundle install

最後のbundle installが上手くいかなかったら、sudoをつけるべし

$ sudo bundle install

ワイはこれで解決できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?