MySQL忘记密码重置管理员密码

本文详细介绍在不同MySQL版本(5.5, 5.6, 5.7)下,如何通过忽略授权表启动服务,进入无密码状态,进而更新root用户密码的步骤。覆盖单实例与多实例场景,提供实用的SQL命令与操作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MySQL 5.5 5.6修改方法
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-table #忽略授权表启动
mysql -uroot

update mysql.user set password=PASSWORD("6") where User='root' and host='localhost';

mysql> flush privileges;

多实例修改忘记root密码方法
mysqladmin -uroot -p222222 -S /data/3306/mysql.sock shutdown
mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-table &
mysql -uroot -S /data/3306/mysql.sock
update mysql.user set password=PASSWORD(“222222”) where User=‘root’ and host=‘localhost’;

cd /data/3306/
./mysql start
mysql -uroot -p222222 -S /data/3306/mysql.sock

MySQL 5.7 修改方法
/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables --skip-networking &
注:–skip-grant-tables 忽略授权表
–skip-networking 禁止远程网络连接(可以不加这个参数)

登录并修改
mysql
flush privileges;

alter user root@'localhost' identified by '1';

grant all on *.* to root@'localhost' identified by '2';

注:因为MySQL密码字段已经不是password 变成了authentication_string
所以也可以按照5.6的方法来该

update mysql.user set authentication_string=PASSWORD("3") where user='root' and host='localhost';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值