ざっくりん雑記

プログラミングで忘れそうなことをひたすらメモる

Mac - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

動作環境

突然MySQLが起動しなくなった

# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解決方法

/tmp/mysql.sockがないことが原因なので作る

$ sudo touch mysql.sock
$ sudo mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/xxxxx.local.pid).

今度は権限が適切に与えられていないため、権限を付与する

$ sudo chown -R _mysql:_mysql /usr/local/var/mysql
$ sudo mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
. SUCCESS!

MySQLサーバーが無事立ち上がったのでログインしてみる

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.13 Homebrew

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

動いた!

参考