LoginSignup
0
2

More than 1 year has passed since last update.

MySQLが起動しなくなった!!

Last updated at Posted at 2021-05-11

こんにちは!

今朝PHPの環境を構築していたところ、
MySQLが起動しなくなった!!!というトラブルが発生し、色々と調べて解決しましたので
その記録を残しておこうと思います

なんでもこの起動エラー、皆様にも発生する可能性が十分にあり得ますので
発生しても焦らないでくださいね

発生エラー

% mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)

mysqlに接続できなくなりました。
'/tmp/mysql.sock'を通じてローカルmysqlサーバーに接続できなかったよ
という日本語訳になります。

環境

  • homebrewインストール済み
  • macOS Big Sur ver.11.2.3

ネットで様々調べていると、ここでいきなり解決に走る記事が多いですが、
念の為現状を確認をしておきましょう
確認なので、エラーが出て当然です

現状確認

% sudo mysql.server restart # 再起動してみる
ERROR! MySQL server PID file could not be found!
Starting MySQL.... ERROR! The server quit without updating PID file (/usr/local/var/mysql/itoutakahironoMacBook-Pro.local.pid).
% ps aux | grep mysql   # mysqlが動いているか確認する(プロセスの確認)
zsh: bus error  ps aux | 
zsh: exit 1     grep mysql
% brew doctor  # brewの一般的な問題をチェック

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  ilmbase
  mysql@5.6

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  imath
  openexr

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/share/man/man5/package-locks.5
  /usr/local/share/man/man5/shrinkwrap-json.5

一旦、記憶も整理しておきましょう

# 何か設定を変更した記憶はあるか → ない
# アップグレードした記憶はあるか → 今朝PHPのインストールをした際に動いてしまったかも…

大事なことは、自分で何か触った記憶はあるかという点だけにしておきます笑

色々と設定をイジる解決方法が見つかりますが、そもそも触ってないんだからここは間違ってないのでは??
という私の見解です

では、MySQLをもう一度見ていきます

# mySQLのバージョンを確認する
% cd /tmp/
% brew list | grep mysql
mysql@5.6   # 私のはver.5.6という事ですね

mySQLをアンインストールして、再度インストールしてみる

 % brew uninstall mysql
Error: No available formula or cask with the name "mysql".

できませんね…

# brewをclean upする
% brew cleanup
Removing: /usr/local/Cellar/glib/2.66.7... (441 files, 20.8MB)
Warning: Skipping heroku/brew/heroku: most recent version 7.53.1 not installed
Removing: /Users/takahiro/Library/Caches/Homebrew/heroku--7.52.0.tar.xz... (7.2MB)
Removing: /usr/local/Cellar/python@3.9/3.9.2_1... (3,942 files, 66MB)
Warning: Skipping ruby-build: most recent version 20210510 not installed
Removing: /Users/takahiro/Library/Caches/Homebrew/ruby-build--20210423... (54.6KB)
Pruned 2 symbolic links and 12 directories from /usr/local

なんだか良い影響をもたらしたような気がしません

解決していく

では、brew doctorのおっしゃる通り

Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  ilmbase
  mysql@5.6

「下のやつが非推奨か無効になってるから、代わりのもの持ってこいよ」 という意味ですね
ここを対処しましょう

# mysql@5.6をもう一回インストールする
% brew install mysql56
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 4 formulae.

うまく通りました。
インストールというより、アップデートですね

# このmysql@5.6を起動してみる
% brew services start mysql@5.6
Service `mysql@5.6` already started, use `brew services restart mysql@5.6` to restart.

ん?もう起動されてる? 一応再起動しておきます

% brew services restart mysql@5.6
Stopping `mysql@5.6`... (might take a while)
==> Successfully stopped `mysql@5.6` (label: homebrew.mxcl.mysql@5.6)
==> Successfully started `mysql@5.6` (label: homebrew.mxcl.mysql@5.6)

動いてる!!

% sudo mysql.server start
Starting MySQL
. SUCCESS! 

動いてる!!

というわけで、解決いたしました。

ネットには、
- sockを自分で生成する
- pidを自分で生成する
という解決方法が多数出てきますが、これでも不具合は起きてしまう事があるそうです

私は再インストールで治りました
でも皆さんは違うかもしれません

皆様も
ネットの記事をそのまま実行せず
状況把握もしっかりと行いましょうね

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