MySQL8.0修改密码问题

MySQL5.7和之前的用户修改密码方式:

mysql -uroot -e "Set password=password(‘123’);"
mysql -uroot -p123.com -e "use mysql;update user set authentication_string=password('456') where user='root';"
update mysql.user set authentication_string=password("123") where user='root';

以上三种方法在MySQL8.0以后版本中将不能使用,如果使用了将会导致在正确修改密码是报如下错误:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'

如遇上以上问题请使用update语句先清空authentication_string字段,然后再修改密码即可

update user set authentication_string='' where user='root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

所以特别提醒童鞋们:

MySQL8.0后请使用alter修改用户密码,因为在MySQL8.0以后的加密方式为caching_sha2_password,如果使用update修改密码会给user表中root用户的authentication_string字段下设置newpassowrd值,当再使用alter user 'root'@'localhost' identified by 'newpassword'修改密码时会一直报错,必须清空后再修改,因为authentication_string字段下只能是MySQL加密后的43位字符串密码,其他的会报格式错误,所以在MySQL8.0以后能修改密码的方法只能是:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值