报错如下图所示:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyP@ssw0rd8';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
解决方法:
1、查询用户:select user,host from user;
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
2、 把'root'@'localhost'改成 'root'@'%',重新运行一遍。如果还是不行,接着往下操作。
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'MyP@ssw0rd8';
3、把密码设置为空然后刷新权限
mysql> update user set authentication_string='' where user='root';
mysql> flush privileges;
4、重新再修改密码:mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'MyP@ssw0rd8';
希望能够帮助到你,谢谢~