MySQL8不小心删除了root账户的操作方式
MUKE
这个人很懒,什么都没有留下。
MUKE
2023-04-18 11:19:46
495
{{single.collect_count}}

在操作MySQL8时误删除root用户,如何进行恢复,解决方法如下。

1、首先在/etc/my.cnf文件中 mysqlID下面添加

skip-grant-tables

2、在终端重启mysql服务

[root@master2]# cd /www/server/mysql/bin
[root@master2 bin]# systemctl restart mysqld.service

3、使用mysql直接进入mysql

[root@master2 bin]# mysql

4.创建root用户

mysql> create user 'root'@'localhost' identified by '123456';

5.执行缓冲刷新

mysql> flush privileges;

6.设置root用户权限

mysql> grant all on *.* to 'root'@'localhost';

 7.查看root用户权限,完美解决

mysql> select * from mysql.user where user='root'\G;
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}