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.

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

Posted at

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.
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?