误删除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('123') 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! [1]+ 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 insert into mysql.user(user,host,password,ssl_type,ssl_cipher,x509_issuer,x509_subject) values('root','localhost',PASSWORD('123'),'','','',''); mysql> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 | +------+-----------+-------------------------------------------+ 1 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! [1]+ 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> ####################误删除所有用户 end#####################################