Quantcast
Channel: 初心者タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 21093

MySQL Access denied for user 'root'@'localhost' の対応

$
0
0

MySQLでエラーが出てハマったのでその対応。

まずは権限なしで立ち上げられるように設定

$ mysqld_safe --skip-grant-tables &
[1] 11541
2020-02-11T04:59:48.6NZ mysqld_safe Logging to '/usr/local/var/mysql/***
2020-02-11T04:59:48.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql

MySQLにログイン

$ mysql -u root

root@localhostのユーザーを一旦削除してから作り直し、全ての権限を与える。

mysql> DROP USER root@localhost;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
Query OK, 0 rows affected (0.00 sec)

その後、下記コマンドを打つとパスワードを求められるので、パスワードを入れてログインできればOK!

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.

Viewing all articles
Browse latest Browse all 21093

Trending Articles