Saturday, October 11, 2008

Reset Mysql password on Linux system

1. Stop Mysql If it is runnung ...
# service mysqld stop


2.Run Mysql With Skip Grant Table option...
# mysqld --skip-grant-tables -u root &

3.Connect With Mysql Client...
# mysql -u root

4.Change The Password and exit...
mysql> update mysql.user set password=PASSWORD('sushil') where user='root';
Query OK, 3 rows affected (0.03 sec)
Rows matched: 3 Changed: 3 Warnings: 0

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

mysql> exit
Bye


5.Stop Mysql ...
# service mysqld stop


6.Start Mysql As Normal (without skip Grant table option)...
# service mysqld start
Starting MySQL: [ OK ]


7.Connect With Mysql Client...
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye


You have done it , Enjoy the Mysql :)