首页 > 数据库技术 > 详细

Mysql 误删用户故障解决方案

时间:2020-07-09 20:16:03      阅读:103      评论:0      收藏:0      [点我收藏+]

误删一下所有用户

# 删除一个用户(::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

Mysql 误删用户故障解决方案

原文:https://www.cnblogs.com/zzzwqh/p/13275636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!