LoginSignup
18
17

More than 5 years have passed since last update.

[MySQL]homebrewでインストールしたMySQLが起動できなくなった話

Posted at

 はじめに

辺りを試してみてもMySQLが起動できなくなったので備忘録的に。
ちなみに発生したエラーメッセージは次の通り。

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  ... /tmp/mysql.sock がない時に発生した

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
  ... /tmp/mysql.sock を作った後に発生した

ERROR! The server quit without updating PID file (/usr/local/var/mysql/xxxxx.pid).
  ... mysql.server start した時に発生した
項目 バージョン
Mac macOS Mojave 10.14.1
Homebrew 1.8.4
MySQL mysql Ver 14.14 Distrib 5.7.24, for osx10.14 (x86_64) using EditLine wrapper

試したこと

確認に使ったコマンド

console
# MySQLのパスが通っているか
which mysql
# => /usr/local/opt/mysql@5.7/bin/mysql

# MySQLサービスが起動しているか
mysql.server status
# => SUCCESS! MySQL running (xxxx)

# プロセスが稼働しているか
ps aux|grep mysql

結論

/usr/local/var/mysql をディレクトリごと消去して再インストールしたらうまくいきました。

console
sudo rm -rf /usr/local/var/mysql
brew uninstall mysql@5.7
brew install mysql@5.7
brew services start mysql@5.7   
mysql.server start                                                              
mysql -uroot                    

ダメだったこと

アンインストール&再インストール

console
brew uninstall mysql@5.7
brew install mysql@5.7

パーミッション・所有権変更

console
sudo chmod -R 777 /usr/local/var/mysql
sodo chown _mysql:_mysql /usr/local/var/mysql

/tmp/mysql.sock を作成・権限変更

console
sudo touch /tmp/mysql.sock
sudo chmod -R 777 /tmp/mysql.sock
sodo chown _mysql:_mysql /tmp/mysql.sock

MySQL関係のディレクトリを全消去

こちら を参考に関連ディレクトリを削除。

18
17
1

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
18
17