質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
rbenv

rbenvは、Rubyバージョン管理ツール。プロジェクトごとでRubyバージョンを切り替えることが可能です。RVMよりもシンプルで、少ない機能で動作します。本体にはRubyのビルド機能は備わっておらず、ruby-buildというツールを用いる必要があります。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1376閲覧

rails db:createのエラー

obr-note

総合スコア16

rbenv

rbenvは、Rubyバージョン管理ツール。プロジェクトごとでRubyバージョンを切り替えることが可能です。RVMよりもシンプルで、少ない機能で動作します。本体にはRubyのビルド機能は備わっておらず、ruby-buildというツールを用いる必要があります。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

1クリップ

投稿2020/03/17 10:03

railsでアプリの作成を開始しましたが、エラーが出て前に進めません。
原因や解決方法が分かればご教示ください!

①聞きたいことのまとめ

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

のエラーを解決したい。

②起きている問題

データベースはMySQLを使用

railsアプリ作成中に、MySQLの権限まわりでエラーが多発するので、下記の記事を参考にMySQLを再インストール(最初はエラー解決を目指していたが、時間がもったいない+重要なデータが無いので再インストールすることにした)
https://qiita.com/akiko-pusu/items/aef52b723da2cb5dc596
※エラーが多発するのは、以前Udemyの講座https://www.udemy.com/share/101ZvECEIdclxRTXw=/
で権限をいじったからだと思われる

MySQLの再インストールが完了したのち、改めてアプリを作成

rails _5.2.4.1_ new bulletinboard --database=mysql --skip-test

でアプリを作成。その後、

rails db:create

でデータベースを作成しようとしたところ、以下のエラーが発生し直らなくなった

% rails db:create rails aborted! 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 /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require' /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require' /Library/Ruby/Gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:174:in `require' /Users/machoair/Work/bulletinboard/config/application.rb:18:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49:in `require_relative' /Users/machoair/Work/bulletinboard/Rakefile:four:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load' /Library/Ruby/Gems/2.6.0/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:22:in `block in perform' /Library/Ruby/Gems/2.6.0/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /Library/Ruby/Gems/2.6.0/gems/railties-5.2.4.1/lib/rails/command.rb:48:in `invoke' /Library/Ruby/Gems/2.6.0/gems/railties-5.2.4.1/lib/rails/commands.rb:18:in `<main>' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' /Library/Ruby/Gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require' /Users/machoair/Work/bulletinboard/bin/rails:nine:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:seven:in `call' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' /Library/Ruby/Gems/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' /Users/machoair/Work/bulletinboard/bin/spring:15:in `<top (required)>' bin/rails:three:in `load' bin/rails:three:in `<main>' (See full trace by running task with --trace)

③ソースコード(関連するソースコード/全ソースコード)

④問題解決するために試したこと(コードもあれば追記)

エラー内容をgoogle翻訳して見たが、意味がさっぱり分からず

まずは、/Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundleのファイルの中身を確認したが、文字化けして意味が分からない

次に、/usr/local/opt/mysql/lib/libssl.1.1.dylibのファイルを探したところ、ファイルが存在していない。。。これが原因か?

しかし、何をすればいいのか分からないので、エラー文でググって
https://qiita.com/kota-es/items/98ae6ee84fc59aaae2ea
を参考に

brew update && brew upgrade

しかし、解決できず

https://qiita.com/utsu_jimmy/items/a35437faea1c0d2f357d
を参考に

rbenv install 2.6.3

でrubyごと再インストール
しかし、解決できず

⑤問題について自分なりに考えたこと

/usr/local/opt/mysql/lib/libssl.1.1.dylibのファイルが見つからないことが原因だと思いますが、
全く検討がつきません。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

technocore

2020/03/17 13:38

・以前はruby-MySQLが動いていたようですから、同じ手順でできないのですか? ・/usr/local/opt/mysql/lib/libssl.1.1.dylibのファイルが見つからない homebrewでmysqlをインストールしたらそのファイルがあるはずですが。 ・bundle installや、rails newでエラーは出ませんでしたか? ・ファイルの中身を確認したが、文字化けして意味が分からない  bundleファイルはバイナリ形式なのでエディタでは文字化けします
obr-note

2020/03/18 00:33

コメントいただきありがとうございます。 後ほどご指摘いただいた点を試してみます。 取り急ぎ、お礼申し上げます。
obr-note

2020/03/18 09:14

ご指摘いただいた点を参考に解決できました。 ありがとうございました。
obr-note

2020/03/18 09:19

宜しければベストアンサーにさせていただきたいのですが、回答欄に適当に投稿いただけないでしょうか? 宜しくお願い致します。
guest

回答1

0

ベストアンサー

>ご指摘いただいた点を参考に解決できました。
>宜しければベストアンサーにさせていただきたいのですが
ありがとうございます。他の人の役に立つよう、解決方法の提示をお願いします。

・以前はruby-MySQLが動いていたようですから、同じ手順でできないのですか?
・/usr/local/opt/mysql/lib/libssl.1.1.dylibのファイルが見つからない
homebrewでmysqlをインストールしたらそのファイルがあるはずですが。
・bundle installや、rails newでエラーは出ませんでしたか?
・ファイルの中身を確認したが、文字化けして意味が分からない
bundleファイルはバイナリ形式なのでエディタでは文字化けします

投稿2020/03/18 09:22

technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

obr-note

2020/03/18 09:39

初心者なので、いろいろ試してしまいました。良く覚えて無いのですが、だいたい下記の手順です。 他の方の参考にはあまりならないかもしれません。。。 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 ``` で無事にデータベースが作成できました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問