Mysql之误删root用户-yellowcong

版权声明:本文为博主yellowcong原创文章,未经博主允许不得转载。 https://blog.csdn.net/yelllowcong/article/details/84400594

今天手残,一不小心,把root用户给干掉了,解决办法,就是先创建root用户,然后进行授权操作。

免密登陆

vim /etc/my.cnf


#在[mysqld] 配置免密登陆
skip-grant-tables

#重启mysql 
systemctl restart mysql

在这里插入图片描述

创建root用户

#使用mysql 这个数据库
use mysql

#插入用户
insert into mysql.user(host,user,password) values("localhost","root",password("admin"));

flush privileges;

#授权到root用户
grant all on *.* to root@localhost;


#重启mysql服务
systemctl restart mysql

使用mysql这个数据库

在这里插入图片描述

给用户添加权限
在这里插入图片描述

可以看到root用户又可以愉快得操作数据库了
在这里插入图片描述

常见问题

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

导致这个问题得原因是,我们再 --skip-grant-tables得状态下,需要刷新一下权限flush privileges;,就可以授权了,
在这里插入图片描述

参考文章

https://blog.csdn.net/yitakabe/article/details/50817874

猜你喜欢

转载自blog.csdn.net/yelllowcong/article/details/84400594