How to Set MySQL root Password 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 set root password for MySQL. Please take a look of this post on “How to Delete Anonymous Users From 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> set password for [email protected]'localhost'=password('password');
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set password for [email protected]'127.0.0.1'=password('password');
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set password for [email protected]'centos6.2'=password('password');
    Query OK, 0 rows affected (0.00 sec)
    
    
    mysql> select user,host,password from mysql.user;
    +---------------+-----------+-------------------------------------------+
    | user          | host      | password                                  |
    +---------------+-----------+-------------------------------------------+
    | root          | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root          | centos6.2 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root          | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    |               | localhost |                                           |
    |               | centos6.2 |                                           |
    +---------------+-----------+-------------------------------------------+
    7 rows in set (0.00 sec)
    
    mysql> select user,host,password from mysql.user;
    +---------------+-----------+-------------------------------------------+
    | user          | host      | password                                  |
    +---------------+-----------+-------------------------------------------+
    | root          | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root          | centos6.2 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    | root          | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
    |               | localhost |                                           |
    |               | centos6.2 |                                           |
    +---------------+-----------+-------------------------------------------+
    5 rows in set (0.00 sec)
    
    mysql> exit
    Bye
    


Leave a Reply