How to rebuild local users and remote users by mysql
This article mainly introduces "how mysql rebuilds local users and remote users". In daily operation, I believe that many people have doubts about how mysql reconstructs local users and remote users. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how mysql rebuilds local users and remote users". Next, please follow the editor to study!
1. Simulated deletion and destruction of users:
Laojiang:~ # mysql-uroot-proot
Mysql > use mysql
Mysql > select user,host from user
+-+ +
| | user | host |
+-+ +
| | laojiang |% | |
| | laojiang | 127.0.0.1 | |
| | root | 127.0.0.1 | |
| | root |:: 1 |
| | root | laojiang |
| | laojiang | localhost |
| | root | localhost |
| | laojiang | laojiang |
+-+ +
8 rows in set (0.00 sec)
Mysql > delete from user where user='root'
Query OK, 4 rows affected (0.00 sec)
Mysql > select user,host from user
+-+ +
| | user | host |
+-+ +
| | laojiang |% | |
| | laojiang | 127.0.0.1 | |
| | laojiang | localhost |
| | laojiang | laojiang |
+-+ +
4 rows in set (0.00 sec)
Mysql >
Laojiang:~ # service mysql restart
Shutting down MySQL.. Done
Starting MySQL. Done
Laojiang:~ # mysql-uroot-proot
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Laojiang:~ #
2. Rebuild local users:
Laojiang:/etc # vi my.cnf
[mysqld]
Skip-grant-tables
Laojiang:~ # service mysql restart
Shutting down MySQL.. Done
Starting MySQL.
Laojiang:~ # mysql-uroot-p
Enter password:
Mysql > insert into mysql.user (host, user, password,ssl_cipher,x509_issuer,x509_subject) values ('localhost',' root', password ('root'),')
Query OK, 1 row affected (0.00 sec)
Mysql > flush privileges
Query OK, 0 rows affected (0.00 sec)
Mysql > grant all privileges on *. * to 'root'@'localhost' identified by' root' with grant option
Query OK, 0 rows affected (0.00 sec)
Mysql >
Laojiang:/etc # vi my.cnf
[mysqld]
# skip-grant-tables
Laojiang:~ # service mysql restart
Shutting down MySQL.. Done
Starting MySQL. Done
Third, rebuild the remote user through the local user:
Laojiang:~ # mysql-uroot-proot
Mysql > select user,host from mysql.user
+-+ +
| | user | host |
+-+ +
| | laojiang |% | |
| | laojiang | 127.0.0.1 | |
| | laojiang | localhost |
| | root | localhost |
| | laojiang | laojiang |
+-+ +
5 rows in set (0.00 sec)
Mysql > grant all privileges on *. * to 'root'@'%' identified by' root' with grant option
Query OK, 0 rows affected (0.00 sec)
Mysql > select user,host from mysql.user
+-+ +
| | user | host |
+-+ +
| | laojiang |% | |
| | root |% | |
| | laojiang | 127.0.0.1 | |
| | laojiang | localhost |
| | root | localhost |
| | laojiang | laojiang |
+-+ +
6 rows in set (0.00 sec)
Mysql >
At this point, the study on "how mysql rebuilds local and remote users" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!