0
0

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.

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

Posted at

##環境
mysql 8.0
Catalina 10.15.6

##遭遇したエラー

~ ❯❯❯ mysql -u user(ユーザー名) -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

当然、ルートでも入ることできず。

~ ❯❯❯ mysql -u root -p                                                                          ✘ 1 
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

内容的にはpidファイルがアクセス拒否で削除できないと怒ってる模様。
サイトを参考にしながら下記の手順で行ってみました。

~ ❯❯❯ mysql.server restart                                                                      ✘ 1 
touch: /usr/local/var/mysql/ユーザー名.pid.shutdown: Permission denied
cat: /usr/local/var/mysql/ユーザー名.pid: Permission denied
 ERROR! MySQL server process # is not running!
override rw-r-----  _mysql/_mysql for /usr/local/var/mysql/ユーザー名.pid? 
Starting MySQL
 SUCCESS! 
~ ❯❯❯ /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
cat: /usr/local/var/mysql/ユーザー名.pid: Permission denied
rm: /usr/local/var/mysql/ユーザー名.pid: Permission denied
2020-09-13T09:14:24.6NZ mysqld_safe Fatal error: Can't remove the pid file:
/usr/local/var/mysql/ユーザー名.pid.
Please remove the file manually and start /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe again;
mysqld daemon not started
/usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied

自らの手で削除してあげる。

~ ❯❯❯ sudo rm /usr/local/var/mysql/ユーザー名.pid.                                                ✘ 1 
Password:
rm: /usr/local/var/mysql/ユーザー名.pid.: No such file or directory
~ ❯❯❯ sudo rm /usr/local/var/mysql/ユーザー名.pid                                                 ✘ 1 

サーバーの立ち上げをしてみましたが、エラーが出ました。

~ ❯❯❯ mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
./usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
/usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
/usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 199: /usr/local/var/mysql/ユーザー名.err: Permission denied
/usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/ユーザー名.pid).

今度はpidファイルがないと怒ってるので作成してあげる。
その上でchmodコマンドで権限も弄りましたが、これは考えなしにやってるので必要なければ必要はないと思います。

~ ❯❯❯ sudo touch /usr/local/var/mysql/ユーザー名.pid
~ ❯❯❯ sudo chmod 777 /usr/local/var/mysql/ユーザー名.pid

再度サーバーを立ち上げ直す

~ ❯❯❯ mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
./usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
rm: /usr/local/var/mysql/ユーザー名.pid: Permission denied
2020-09-13T09:19:00.6NZ mysqld_safe Fatal error: Can't remove the pid file:
/usr/local/var/mysql/ユーザー名.pid.
Please remove the file manually and start /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe again;
mysqld daemon not started
/usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/ユーザー名.err: Permission denied
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/ユーザー名.pid).
~ ❯❯❯ sudo mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
.. SUCCESS! 

お疲れ様でした!!

##参考にさせていただいたサイト
https://qiita.com/carotene4035/items/e00076fe3990b9178cc0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?