[MySQL] MySQL deletes anonymous users to ensure login security
Many MySQL programs use the anonymous logon function. After installing MySQL, you can log on to the database.
This is basically nothing for MySQL, but this login method is definitely not available when we want to deploy the database! Think about it. If your database can be accessed at will, I think you will receive a call in the middle of the night, saying there is a problem with the data!
The following describes how to delete Anonymous Users:
First, run the command to enter the database.
[root@localhost raul]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Switch the database to mysql.
mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed
Before deleting a database, we should first check the database user table to see the existence of the user.
mysql> select user, host from user;+------+-----------------------+| user | host |+------+-----------------------+| root | 127.0.0.1 || | localhost || root | localhost || | localhost.localdomain || root | localhost.localdomain |+------+-----------------------+5 rows in set (0.00 sec)
As we can see, some rows in the user column are empty. This is the anonymous user ~! In this step, we have found an anonymous user. The remaining operation is to delete the user and ensure login security.
mysql> delete from user where user='';Query OK, 2 rows affected (0.00 sec)
At this time, the execution status of mysql shows that we have deleted two rows of data, and then executed the query command to check whether the deletion was successful.
mysql> select user, host from user;+------+-----------------------+| user | host |+------+-----------------------+| root | 127.0.0.1 || root | localhost || root | localhost.localdomain |+------+-----------------------+3 rows in set (0.00 sec)
OK! Deleted successfully