mysql数据库恢复用户_二.误删除MySQL用户,恢复方法

误删除MySQL用户导致无法进入数据库

一.方法一

1.停止数据库

[root@db02 ~]# /etc/init.d/mysqld stop

2.跳过授权表,跳过网络启动数据库

[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &

3.连接数据库

[root@db02 ~]# mysql

4.插入新的root用户

insert into mysql.user values ('localhost','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N');

5.重新启动MySQL

[root@db01 ~]# mysqladmin shutdown

[root@db01~]# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

二.方法2

1.停止数据库

[root@db02 ~]# /etc/init.d/mysqld stop

2.跳过授权表,跳过网络启动数据库

[root@db02 ~]# mysqld_safe --skip-grant-tables --skip-networking &

3.连接数据库

[root@db02 ~]# mysql

4.刷新授权表

mysql> flush privileges;

5.创建root超级用户

mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;

6.重启数据库

[root@db01 ~]# mysqladmin -uroot -p123 shutdown;

[root@db01~]# /etc/init.d/mysqld start

三.方法3(前提是数据库没有数据)

1.停止数据库

[root@db02 ~]# /etc/init.d/mysqld stop

2.删文件

[root@db02 ~]# rm -rf /application/mysql/data/

3.初始化环境

[root@db02 ~]#./mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data

4.启动mysq

[root@db02 scripts]# /etc/init.d/mysqld start

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值