正常状态:mysql
[root@web01 data]# mysql-uroot -p123456web
Warning: Using apassword on the command line interface can be insecure.sql
Welcome to the MySQLmonitor. Commands end with ; or \g.ide
Your MySQL connection idis 75wordpress
Server version: 5.6.34Source distributionui
Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved.spa
Oracle is a registeredtrademark of Oracle Corporation and/or itsinput
affiliates. Other namesmay be trademarks of their respectiveit
owners.io
Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.
mysql> selectuser,host from mysql.user;
+-----------+--------------------------+
| user | host |
+-----------+--------------------------+
| root | 127.0.0.1 |
| wordpress |172.16.1.0/255.255.255.0 |
| root | ::1 |
| | localhost |
| root | localhost |
| | web01 |
| root | web01 |
+-----------+--------------------------+
7 rows in set (0.00 sec)
管理员用户被误删除后:
mysql> drop userroot@localhost;
Query OK, 0 rowsaffected (0.07 sec)
mysql> selectuser,host from mysql.user;
+-----------+--------------------------+
| user | host |
+-----------+--------------------------+
| root | 127.0.0.1 |
| wordpress |172.16.1.0/255.255.255.0 |
| root | ::1 |
| | localhost |
| | web01 |
| root | web01 |
+-----------+--------------------------+
6 rows in set (0.00 sec)
解决:
须要使用root@127.0.0.1用户登陆系统(无密码),再建立root@localhost
[root@web01 data]# mysql-h 127.0.0.1 -uroot -p
Enter password:
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQL connection idis 80
Server version: 5.6.34Source distribution
Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registeredtrademark of Oracle Corporation and/or its
affiliates. Other namesmay be trademarks of their respective
owners.
Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql> selectuser,host,password from mysql.user;
+-----------+--------------------------+-------------------------------------------+
| user | host | password |
+-----------+--------------------------+-------------------------------------------+
| root | web01 | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | web01 | |
| wordpress |172.16.1.0/255.255.255.0 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+--------------------------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> grant all on*.* to root@localhost identified by '123456' with grant option; #建立被删除的用户,并赋予超级权限
Query OK, 0 rowsaffected (0.00 sec)
mysql> flushprivileges;
Query OK, 0 rowsaffected (0.00 sec)
mysql> quit
Bye
恢复正常
[root@web01 data]# mysql-uroot -p123456
Warning: Using apassword on the command line interface can be insecure.
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQL connection idis 81
Server version: 5.6.34Source distribution
Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registeredtrademark of Oracle Corporation and/or its
affiliates. Other namesmay be trademarks of their respective
owners.
Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.
mysql> selectuser,host from mysql.user;
+-----------+--------------------------+
| user | host |
+-----------+--------------------------+
| root | 127.0.0.1 |
| wordpress |172.16.1.0/255.255.255.0 |
| root | ::1 |
| | localhost |
| root | localhost |
| | web01 |
| root | web01 |
+-----------+--------------------------+
7 rows in set (0.00 sec)
欢迎加入qq群:202932777,一块儿交流,一块儿进步!!!