Reset MySQL password in Linux

5 11 2009

You may follow the steps given below to reset MySQL root use password.

1. Login to the server through SSH.

2. Stop MySQL service.

/etc/rc.d/init.d/mysql stop [or]
/etc/rc.d/init.d/mysqld stop

3. Now start MySQL service using the following command.

/usr/bin/mysqld_safe –skip-grant-tables

Note: In some servers, it will be “/usr/bin/safe_mysqld –skip-grant-tables“.

4. Now login to the server in another console and execute the following command.

/usr/bin/mysql -u mysql

5. You will get MySQL prompt and execute the following queries to reset the password.

UPDATE user SET Password=PASSWORD(‘new_password’) WHERE Host=’localhost’ AND User=’root’;
flush privileges;

Output:
~~~~~~~~~~~~~~~~
mysql> UPDATE user SET Password=PASSWORD(‘new’) WHERE Host=’localhost’ AND User=’root’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

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

mysql> quit
~~~~~~~~~~~~~~~~

6. Kill the running MySQL process “pkill mysql” [or] “pkill mysqld.

7. You can start MySQL using the following command.

/etc/rc.d/init.d/mysql start [or]
/etc/rc.d/init.d/mysqld start

8. Now you can access MySQL as root user.

# mysql -u root -p
Enter password:
mysql>



Actions

Information

Leave a comment