Mysql 忘记密码的处理方法总结

    有时候我们安装好MySQL数据库后,root密码可能记不清楚了,就无法登陆进去. 这个时候该怎么解决呢 ?
    以下是解决方法供参考:
  1. 首先停止MySQL服务
    命令: `systemctl stop mysqld
  2. 编辑配置文件:vim /etc/my.cnf`
    增加一行:
    [mysqld]
    skip-grant-tables
    保存文件, 重新启动MySQL.
systemctl  start  mysqld 

使用mysql 登陆到系统中去, 只输入MySQL命令即可, 不用用户名密码
在这里插入图片描述
执行修改密码语句:

 update mysql.user set authentication_string=password('aaa123')   where user='root' and host='localhost';

修改后需要刷新权限表:
flush privileges ;
退出MySQL:
quit

停止MySQL服务, 修改配置文件my.cnf , 把skip 那行去掉. 保存文件, 重启mysqld 服务.
再次登陆就需要密码了, 输入我们刚才更新后的密码即可登陆到系统.
在这里插入图片描述
以上供参考.

猜你喜欢

转载自blog.csdn.net/weixin_50764555/article/details/111841396