How to Delete Anonymous Users From MySQL on CentOS 6.2

Share this Article :

MySQL installation has a default “root” user with a blank password and an “anonymous” user, also with a blank password. This is very unsecured and not recommended. In order to protect your data, the “root” user should be set with a password and the anonymous user should be delete. In this post, i will show on how to delete Anynymous users from MySQL. Please take a look of this post if you want to “set root password for MySQL

    [[email protected] ~]# 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
    


Leave a Reply