MySQL is a popular open-source database management system used by many web applications. By default, MySQL creates an anonymous user account with no password, which can be a security risk.
In this guide, we will show you how to delete anonymous users from MySQL on CentOS 6.2.
Step 1: Access MySQL as the Root User
The first step is to access the MySQL server as the root user. Run the following command in your terminal:
mysql -u root -p
This command will prompt you to enter the MySQL root user password. Enter the password and press Enter to log in.
Step 2: View Existing Users
Next, you need to view the existing MySQL users. Run the following command:
SELECT user,host FROM mysql.user;
This command will show you a list of all the users in the MySQL user table.
Step 3: Delete Anonymous Users
Now that you have a list of users, you can delete the anonymous user accounts. Run the following command:
DELETE FROM mysql.user WHERE user='';
This command will delete all the anonymous user accounts from the MySQL user table.
Step 4: Apply the Changes
Finally, you need to apply the changes by running the following command:
FLUSH PRIVILEGES;
This command will reload the MySQL privileges table and apply the changes you made.
Step 5: Exit MySQL
Now that you have deleted the anonymous users, you can exit MySQL by running the following command:
exit
[root@centos6 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 150 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license 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 | | | root | centos6.2 | | | root | 127.0.0.1 | | | | localhost | | | | centos6.2 | | +---------------+-----------+-------------------------------------------+ 7 rows in set (0.00 sec) mysql> delete from mysql.user where user=''; Query OK, 2 rows affected (0.00 sec) mysql> select user,host,password from mysql.user; +---------------+-----------+-------------------------------------------+ | user | host | password | +---------------+-----------+-------------------------------------------+ | root | localhost | | | root | centos6.2 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | | root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | +---------------+-----------+-------------------------------------------+ 5 rows in set (0.00 sec) mysql> exit Bye
Commands Mentioned:
- mysql -u root -p – Access MySQL as the root user
- SELECT user,host FROM mysql.user; – View existing MySQL users
- DELETE FROM mysql.user WHERE user=”; – Delete anonymous users
- FLUSH PRIVILEGES; – Apply the changes
- exit – Exit MySQL
Conclusion
In this guide, we have shown you how to delete anonymous users from MySQL on CentOS 6.2. By following these steps, you can improve the security of your MySQL server by removing the default anonymous user accounts. We recommend that you regularly review the user accounts on your MySQL server and delete any that are no longer necessary.
If you have any comments or suggestions for improvements, please feel free to share them below.