Resetting MySQL Password

Stop all MySQL running process.

$ /etc/init.d/mysqld stop

Run the following command

$ /usr/bin/mysqld_safe --skip-grant-tables &

Mysqld_safe is a mysql that run on a ‘safe mode’. It means that mysql will add extra safety features when mysql is started. It is useful way if your mysql is crashed or an error occurred or if you want to troubleshoot your mysql.

--skip-grant-tables option means that you want to skip the user’s information and privileges exist in mysql database. With this option you can start enter into mysql console without a password.

$mysql –u root

Change the database into mysql.

mysql>use mysql;

Change root password. Please replace mypassword with the password.

mysql>UPDATE user SET password=PASSWORD(‘mypassword’) WHERE user=’root’;

Flush all privileges.

mysql>FLUSH PRIVILEGES;

Exit from MySQL console and kill the currently running mysqld. Start mysqld using SysV method.

$ /etc/init.d/mysqld start

Try login using your new password.

No comments: