MySQL误删了所有用户_MySQL 误删用户故障解决方案

“误删”所有用户

# 删除一个用户(::1 是本机 ipv6 地址)

mysql> drop user root@'::1';

Query OK, 0 rows affected (0.00 sec)

# 删除所有用户

mysql> delete from mysql.user where 1=1;

Query OK, 4 rows affected (0.00 sec)

# 删除用户以后还是可以登陆,但是不要重启,重启就会出现故障报错

解决方式一:

停止数据库

[root@db02 scripts]# systemctl stop mysqld

跳过 授权表 和 网络启动(重要)

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

插入新的用户

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');

重启启动数据库

[root@db02 scripts]# mysqladmin shutdown

200709 16:27:19 mysqld_safe mysqld from pid file /usr/local/mysql/data/db02.pid ended

[1]+ Done mysqld_safe --skip-grant-tables --skip-networking

[root@db02 scripts]# systemctl start mysqld

解决方式二:

停止数据库

[root@db02 scripts]# systemctl stop mysqld

跳过 授权表 和 网络启动(重要)

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

授权一个新用户

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

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

Query OK, 0 rows affected (0.00 sec)

退出

[root@db02 scripts]# mysqladmin -uroot -p123 shutdown

[root@db02 scripts]# systemctl start mysqld

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值