Resetting MySQL password in Linux

After a clean install of MySQL in Fedora 13 I found myself in the position of being unable to set a root password as one had somehow already been created. The situation of forgetting a password is much more likely, never the less the steps are the same:

Kill the mysql service
[root@host /]# service mysqld stop

Start the service with disabled grant tables
[root@host /]# /usr/bin/mysqld_safe --skip-grant-tables &

Open a SQL command prompt
[root@host /]# mysql

Connect to the DB
mysql> use mysql

View users
mysql> SELECT * FROM `user`;

Reset the user password (’root’ can be any user and ‘newpassword’ any password)
mysql> UPDATE `user` SET `password` = PASSWORD('newpassword') WHERE `User` = 'root';

Quit SQL
mysql> exit

Restart the service
[root@host /]# service mysqld restart


About this entry