【自分用メモ】MySQLのエラー色々「ERROR 1045」「ERROR 2002 」

エラーと攻略方法

雑にメモ。

$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

MySQLを停止

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

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

$ mysql.server restart
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.pid).

$ sudo chown mysql:mysql /tmp # 実行しなくていい場合も
$ sudo chown -R _mysql:_mysql /usr/local/var/mysql
$ sudo mysql.server start
Starting MySQL
. SUCCESS!

$ mysql -u root -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

$ mysql -u root                                                                                                                                          
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 Homebrew

Copyright (c) 2000, 2018, 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> 
$ sudo ps aux|grep mysql
$ sudo kill 9999

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

$ sudo rm -rf /usr/local/var/mysql
$ brew uninstall mysql
$ brew install mysql
$ mysql.server start
Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Saneatsus-MacBook-Pro.local.pid).

$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

$ mysql -u root 
:
:
mysql> 

その他

Railsでは config/settings/development.local.yml の中でpasswordを空にしちゃう。

db:
  default:
    username: "root"
    password: ""

参考