mysql8.0 版本忘记密码如何修改密码(与5.7.35版本mysql不同)

第一步:

在mysql的配置文件中/etc/my.cnf 中 [mysqld] 下加入skip-grant-tables这条命令

vim /etc/my.cnf

[mysqld]
skip-grant-tables

第二步:

重启mysqld服务

service mysqld restart

第三步:

直接进入mysql

mysql -uroot 
use mysql
update user set authentication_string='' where user='root';
exit

update user set authentication_string=’’ where user=‘root’;
使用此条命令清除密码为空

第四步:

进入/etc/my.cnf 将skip-grant-tables 注释 重启服务
因为此时将skip-grant-tables注释掉的话修改密码会报错:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

所以我们需要执行:

vim /etc/my.cnf
[mysqld]
#skip-gant-tables
service mysqld restart

第五步:

直接执行进入mysql 执行命令

mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

必须使用这个命令
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
mysql 8.0中无法使用
1.update mysql.user set authentication_string=password(“123”) where user=‘root’;
2.mysql -uroot -p123.com -e “use mysql;update user set authentication_string=password(‘456’) where user=‘root’;”

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值