ERROR 1698(28000):Access denied for user'root'@'localhost'解決方法
問題の説明
以前MySQLサービス端末本体でパスワードを使ってrootアカウントにログインするのは問題ありませんでしたが、今日はどこを動かしたのか分かりません.ログインに失敗し、このエラーコードがあります.
解決策 mysqlサービスを停止 セキュリティモードでMySQL を起動 MySQLが起動するとパスワードなしで にログインできます. userテーブルを見てみると、エラーの原因はここでrootのpluginがauth_に変更されたことです.socket、パスワードでログインしたpluginはmysql_native_password auth_についてsocket、公式に説明があります.https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.htmlああ、どうせ今はしばらく使わないから、ここを変えましょう. サービスを再起動すると、問題は に解決されます.
以前MySQLサービス端末本体でパスワードを使ってrootアカウントにログインするのは問題ありませんでしたが、今日はどこを動かしたのか分かりません.ログインに失敗し、このエラーコードがあります.
~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解決策
~$ sudo systemctl stop mysql
~$ sudo mysqld_safe --skip-grant-tables &
~$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)
mysql> select User, plugin from mysql.user;
+-----------+-----------------------+
| User | plugin |
+-----------+-----------------------+
| root | auth_socket |
| mysql.sys | mysql_native_password |
| dev | mysql_native_password |
+-----------+-----------------------+
3 rows in set (0.01 sec)
mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
~$ sodu systemctl restart mysql
~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)