本文讨论两个报错:Operation ALTER USER failed for 'root'@'%'
与Plugin 'mysql_native_password' is not loaded
报错Operation ALTER USER failed for ‘root‘@’%’
安装mysql后,更改初始密码时,按照教程输入ALTER USER 'root'@'%' IDENTIFIED BY '123';
,报错Operation ALTER USER failed for 'root'@'%'
。(或者输入ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
,报错Operation ALTER USER failed for 'root'@'localhost'
)
解决:在已登录mysql后输入
use mysql
select user,host from user;
如上图,显示user中root
的host为localhost
,则应输入ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
反之,若显示user中root
的host为%
,则应输入ALTER USER 'root'@'%' IDENTIFIED BY '123';
报错Plugin ‘mysql_native_password’ is not loaded
上文中的代码已经避开了接下来讨论的这一个ERROR。实际上,在网上教程中,我查到的代码是ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
,然后遇到报错Plugin 'mysql_native_password' is not loaded
,如下图所示。
我在网上查到的资料中没有线索。这时,我发现有人提到
MySQL5.8从开始将caching_sha2_password替代mysql_native_password作为默认的身份验证插件
于是我将代码中的mysql_native_password
改为caching_sha2_password
,即输入:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123';
成功。
后来我查阅资料,又发现直接省略这部分就行:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';