開発環境
- Rails 7.0.8.7
- Ruby 3.1.5
- Homebrew 4.4.14
- Mysql8.0
読んで欲しい人
- Railsでサーバーを立ち上げようとした時、Console開こうとした時に下記のエラー出た人
Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist` exited with 5.
- Railsから下記のエラーで怒られた人
ActiveRecord::ConnectionNotEstablished: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- 過去の俺
エラーまでの経緯
※ 下記は/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist exited with 5.
エラー出るまでに踏んだ経緯です
最初にbin/dev
を利用してサーバーを立ち上げました。
そうすると下記のエラーが
ActiveRecord::ConnectionNotEstablished: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
言われた通りsocket
が原因で、DBに接続できないのかなぁと思いながらdatabase.yml
の中身を見に行くと
development:
adapter: mysql
database: hoge_development
username: root
password:
encoding: utf8
test:
# 省略
socket
の指定がないではありませんか…なぜか
調べたところによるとmy.cnf
の client
セクションで記述されているから問題ないとのこと
my.cnf
というのはざっくりいうとMySQLの設定ファイルのことです
ログの出力場所などが記述されていたりします
ここまできて、ようやくsocket
の問題ではなさそうだなということに気づきます。
では、そもそもMySQLが動いてるのかをbrew services list
コマンドで確認しに行きます
MySQLのstatus
がstopped
になっていました
なのでbrew services start mysql@8.0
でMySQLを再起動しようとすると下記のログが吐かれます
Warning: Taking root:admin ownership of some mysql@8.0 paths:
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin/mysqld_safe
/opt/homebrew/opt/mysql@8.0
/opt/homebrew/opt/mysql@8.0/bin
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
Warning: mysql@8.0 must be run as non-root to start at user login!
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist` exited with 5.
解決策
ログで指示された通りに下記の手順を踏みました
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin/mysqld_safe
/opt/homebrew/opt/mysql@8.0
/opt/homebrew/opt/mysql@8.0/bin
何のファイルを削除しているのか知らないのも嫌なのでざっくりと調べてみました
-
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin
- MySQLのバイナリファイルが格納されているディレクトリ、ここにはMySQLの実行可能ファイルが含まれている
-
/opt/homebrew/Cellar/mysql@8.0/8.0.40_5/bin/mysqld_safe
- エラー発生時のサーバーの再起動やエラーログ、サーバークラッシュした時の再起動とかを提供してくれるファイル
-
/opt/homebrew/opt/mysql@8.0
- MySQLのシンボリックリンクが格納されているディレクトリ。HomebrewがインストールしたMySQLのバージョンに対するショートカットとかが入っているファイル
-
/opt/homebrew/opt/mysql@8.0/bin
- MySQLのバイナリファイルへのシンボリックリンクが格納されているディレクトリ
上記4つをrm
コマンドで削除します
次に下記を対応します
Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist` exited with 5.
色々と調査したのですが、なぜゆえbootstrap
が出てきたのか、homebrew.mxcl.mysql@8.0.plist
ファイルのどこに問題があったのかは結局分からずじまいでした…
身も蓋もありませんが、ここでbrew uninstall mysql@8.0
の後にbrew install mysql@8.0
で再度インストールします
もろもろ初期設定を行った後にbrew services start mysql@8.0
を行います
すると下記エラー
`Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist` exited with 5.`
嘘だろと思いbrew services list
を確認
mysql@8.0 error root ~/Library/LaunchAgents/homebrew.mxcl.mysql@8.0.plist
statusにerrorが発生していました。
start
がダメならこいつでどうだbrew services restart mysql@8.0
ここでやっとこさMySQLが起動してくれました。
感想
- 全くもって何で解決したか謎なので、いつか再度調査します、多分…
参考