误删除root用户&误删除所有用户

 #-------------------------------------------------------------------------------
#忘记root密码 登录并修改root密码 beign
#------------------------------------------------------------------------------- mysqld_safe --skip-grant-tables --skip-networking &
[root@db01-sa ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> update user set password=PASSWORD('') where user='root' and host='localhost';
Query OK, 1 row affected (0.98 sec)
Rows matched: 1 Changed: 1 Warnings: 0 [root@db01-sa ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.180620 13:09:10 mysqld_safe mysqld from pid file /application/mysql/data/db01-sa.pid ended
.... SUCCESS!
[]+ Done mysqld_safe --skip-grant-tables --skip-networking [root@db01-sa ~]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.38 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> #-------------------------------------------------------------------------------
#忘记root密码 登录并修改root密码 end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#误删除所有用户 beign
#------------------------------------------------------------------------------- #模拟情况
select user,host,password from mysql.user;
mysql> drop user root@'localhost'; #开始处理
[root@db01-sa ~]# /etc/init.d/mysqld stop
[root@db01-sa ~]#mysqld_safe --skip-grant-tables --skip-networking &
[root@db01-sa ~]# mysql mysql> INSERT INTO mysql.user VALUES ('localhost','root',
-> '','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');
Query OK, 1 row affected (0.00 sec) mysql> update mysql.user set password=PASSWORD('') where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+------+-----------+-------------------------------------------+
row in set (0.08 sec) [root@db01-sa ~]# /etc/init.d/mysqld restart
Shutting down MySQL..180620 13:19:15 mysqld_safe mysqld from pid file /application/mysql/data/db01-sa.pid ended
SUCCESS!
Starting MySQL..... SUCCESS!
[]+ Done mysqld_safe --skip-grant-tables --skip-networking
[root@db01-sa ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@db01-sa ~]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.38 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec) #-------------------------------------------------------------------------------
#误删除所有用户 end
#-------------------------------------------------------------------------------

其实做到以上下面的就不用看了

############################################################################

如果遇到以上处理权限不足的补充处理

----add begin  by nod 18-06-21------

备注:可能会有权限不够的情况
处理方式: INSERT INTO mysql.user VALUES ('localhost','root',
'','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'); mysql> update mysql.user set password=PASSWORD('') where user='root'; [root@db01-sa ~]# /etc/init.d/mysqld restart
Shutting down MySQL..180621 08:08:27 mysqld_safe mysqld from pid file /application/mysql/data/db01-sa.pid ended
SUCCESS!
Starting MySQL..... SUCCESS!
[]+ Done mysqld_safe --skip-grant-tables --skip-networking
[root@db01-sa ~]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

----add end  by nod 18-06-21------

05-02 01:40