Mark一下 mysql 误删除root用户的解决方法

恢复MySQL删除的root用户

今天学习mysql用户管理,不小心将mysql.user表中的root用户给删掉了,然后就无法登录mysql了,网上找到了linux下的解决方法,我做了简单的修改,改成了我的windows版,恢复方法如下:

1、关闭mysql服务
net stop mysql 或者 wamp工具关闭
2、启动无需验证用户的特权使用模式
切换到mysql的bin目录,执行mysqld  --console --skip-grant-tables
3、使用root用户登录(没有密码),重新授权
grant all privileges on *.* to root@'localhost' identified by '密码' with grant option;
flush privileges;
exit
注:如果grant 授权报错:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement,请先执行一次flush privileges;,然后再grant授权即可。
4、退出特权模式(Ctrl+C)
5、正常启动mysql,即可恢复使用
 
网上看到的linux的恢复办法
1、关闭mysql
/etc/init.d/mysql stop
2、启动无需验证用户的特权使用模式
/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3、使用root用户登录(没有密码),重新授权
mysql -uroot
grant all privileges on *.* to root@'localhost' identified by '密码' with grant option;
flush privileges;
exit
4、重启mysql服务,即可恢复使用
/etc/init.d/mysql restart

转载于:https://www.cnblogs.com/youngerger/p/8529066.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值