Mysql忘记root密码解决方案

本文详细介绍了如何停止并重启MySQL服务,修改配置文件以临时禁用授权表,设置root用户密码,然后安全地恢复权限。适合初学者和运维人员参考。

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

停止MYSQL

systemctl stop mysqld

修改mysql的配置文件

vim /etc/my.cnf

在[mysqld]下增加

skip-grant-tables

启动MYSQL

systemctl start mysqld

登陆MYSQL

mysql -u root -p

更新ROOT密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '填写密码';
flush privileges;

最后

去掉再my.cnf文件下增加的skip-grant-tables,并重启mysql

其他

If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root. However, this is insecure. For instructions on assigning a password, see Section 2.10.4, “Securing the Initial MySQL Account”.

参考

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值