MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai

Jul 18, 2011

How to set password for root user in mysql database

This explains how to set password for root user from command line interface. 

Login to mysql as root user without password after installing mysql
[root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Changing the root password for the first time
[root@mysql ~]# mysqladmin password abc123

Loging as before without password
[root@mysql ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Loging with new password
[root@mysql ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Changing the current password to another
[root@mysql ~]# mysqladmin -u root -pabc123 password redhat

Dont forget to flush privileges after deleting/modifying users or resetting passwords.

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>


No comments:

Post a Comment