ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘

ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’

即不能通过root来登录mysql

首先用内置用户登录
输入下面的代码可以看到用户和密码
mysql> update mysql.user set authentication_string=PASSWORD(‘newPwd’), plugin=‘mysql_native_password’ where User=‘root’;

sudo cat /etc/mysql/debian.cnf

mysql -u debian-sys-maint -p
//登录后输入下面的代码
select User, plugin from mysql.user;

可以看到root的plugin是auth_socke
关于auth_socke的介绍,链接: link.
要把root的验证方式用以下代码改成本地密码验证

update user set plugin="mysql_native_password" where user='root';

后面就可以开始改root的本地密码了:
很多文章说要先把密码改成空的

use mysql;
UPDATE user SET authentication_string="" WHERE user=“root”;

然后改成自己想要的密码;

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY '新密码';

版权声明:本文为xuemmmm原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。