2
1

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.

【rails db:createエラー】dependent dylib '/usr/local/opt/mysql/lib/libssl.1.1.dylib' not found for '/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle'

Posted at

エラーをいろいろ試して解決しました。(めちゃくちゃな解決法ですが初心者なのでご容赦ください)

エラー内容

$ rails db:create

したところ

LoadError: dlopen(/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): dependent dylib '/usr/local/opt/mysql/lib/libssl.1.1.dylib' not found for '/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle' - /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle

のエラーが発生。
'/usr/local/opt/mysql/lib/libssl.1.1.dylib'のファイルが無い?と書いてありました。

解決方法

他の方の参考にはあまりならないかもしれません。。。

homebrewでmysqlをインストールすれば、/usr/local/opt/mysql/lib/libssl.1.1.dylibファイルができると思い、
https://qiita.com/narikei/items/cd029911597cdc71c516
を参考に

$ brew install mysql
$ mysql.server start
$ bundle init
$ bundle install --path=vendor/bundle

を実施しました。

その後、アプリ内で改めて

$ rails db:create

したら、

Could not find mysql2-0.5.3 in any of the sources
Run `bundle install` to install missing gems.

というエラーが出たので、

$ bundle install

したら、

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

のエラーが出ました。
https://qiita.com/fukuda_fu/items/463a39406ce713396403
を参考に

$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl@1.1/include"
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
$ bundle install

したところ、成功しました。改めて、

$ rails db:create

したところ、

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

のエラーが出たので、
https://qiita.com/carotene4035/items/e00076fe3990b9178cc0
を参考に

$ touch /tmp/mysql.sock
$ mysql.server restart

をした後

$ rails db:create

で無事にデータベースが作成できました。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?