たぶんありがちな話。
でも似たような話がいろいろ転がっていて、どれが自分の症状なのかよくわからなかったので手間取ったorz
現象
- なんかMac重いなーと思って再起動
- 再起動完了!さー開発するぞ
- あれ?ローカル開発環境立ち上がらない・・・
- MySQLにログインできない・・・だと・・・😂
症状
これで落ちてた。なんでだ。
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
環境
OS: macOS High Sierra 10.13.6
MySQL: 5.7.19
解決
事象が起こった要因は結局よくわからなかったが、自分の場合は下記をやることで解決した
そもそもなんで怒られてるのか
Access denied
なので、まあ権限まわりがおかしくなっているんでしょうと推測
であれば、権限なしでも使えるようにしてやればよい
mysqlを止める
sudo mysql.server stop
権限なしで動かせるようにする
sudo mysqld_safe --skip-grant-tables &
mysqlにログイン
mysql -u root
mysql db の users table をチェック
select host, user, authentication_string from user;
passってなんぞ。。。
+-----------+---------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+---------------+-------------------------------------------+
| localhost | root | pass |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+---------------+-------------------------------------------+
消したれ
update user set authentication_string = null where user = 'root'
通常モードで起動し直す
sudo mysql.server stop
sudo mysql.server start
入れた
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 Homebrew
Copyright (c) 2000, 2017, 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>
まとめ
よくわからず使っているのは良くないなと思いました。
ちゃんと勉強しよう。。