macos上 mysql 8.0 重置密码记录

修改密码按大部分教程的操作结束,进行登录的时候还是会出现

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

经过多次尝试,终于解决这个问题。以下是操作过程记录。
关键为第二步。

1. 确保 mysql server 已经停止运行

查询mysql server 是否处于运行状态

sudo /usr/local/mysql/support-files/mysql.server status

如果正在运行,则将其停止

sudo /usr/local/mysql/support-files/mysql.server stop

以 skip-grant-tables 模式启动mysql

sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables 

2. 修改密码

登录 mysql

mysql -u root

设置密码为空

mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
mysql> flush privileges;
mysql> exit;

再次登录 mysql

mysql -u root

更改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
mysql> flush privileges;
mysql> exit;

3. 以正常模式启动 mysql

sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start

至此,就可以正常登录 mysql

mysql -u root -p

参考:
How to reset the root password in MySQL 8.0.11?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lylhw13_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值