mysql修改root密码或者host后无法登陆解决办法


今天在树莓派上安装了mysql之后,发现无论输入密码是否正确,都会报错误:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

在网上找了好久的解决办法,终于成功了,过程如下:

首先将my.ini中在[mysqld]节点上加

skip-grant-tables //主要作用是:跳过表中的验证,可以无密码登陆。

保存并重启mysql 然后直接终端使用mysql命令登录之后查询plugin字段值:

mysql> use mysql;
mysql> select plugin from user where user = 'root';

执行结果plugin字段为空。

更新plugin字段为mysql默认值:

mysql> update user set plugin='mysql_native_password';

更新成功,继续执行更新密码操作:

mysql> update user set authentication_string=password('123456') where user='root' and host='localhost';

刷新权限:

mysql> flush privileges;

将my.ini中的

skip-grant-tables  

注释掉或者删掉,然后重启mysql,密码更新成功.