How to reset root password in MySQL

By default some installations of MySQL server come with no password for the root account. If you have set a password and forgot it you have to use the following procedure to reset it. The procedure is available for mysql instances installed on Linux operating systems. The passwords in MySQL are stored on the user table from the mysql database and are encrypted using the mysql PASSWORD() function. The used encryption algorithm is one way and cannot be reversed.

In this procedure we won’t recover the existing password for the root account but instead we will reset it by changing it with a new one.

1. # /etc/init.d mysql stop

2. # mysqld_safe –skip-grant-tables &

3. # mysql -u root

This will bring us at the mysql console.

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1588
Server version: 5.1.51-0 (Debian)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

4. Run the following queries in order to reset the password:

mysql> use mysql;
mysql> UPDATE user set Password=PASSWORD(”NEW-PASSWORD”) WHERE User=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit;

Note: Replace NEW-PASSWORD with your chosen password for the mysql root account.

Here the UPDATE statement is used to update the “user” table from the mysql database with the new password for the root account. After the password has been updated the FLUSH PRIVILEGES statement is used to reload the privileges from the grant tables in the mysql database.

5. # /etc/init.d/mysql start

6. # mysql -u root -p

and input with new password!! good luck!!

Leave a Reply

:) :( :d :"> :(( \:d/ :x 8-| /:) :o :-? :-" :-w ;) [-( :)>- more »