Tuesday, May 13, 2008

Recover mysql password

Forgot the mysql password??
Not a problem...recover MySQL database server password with following five easy steps.

1: Stop the MySQL server process. Stop instance of the running MySQL.
# /etc/init.d/mysql stop
or
# service mysqld stop
either of this can do.

2: Start to MySQL server using foll:
# mysqld_safe --skip-grant-tables &

This will start the mysql in safe mode and will not ask for the password

3: Connect to mysql from the command prompt:
# mysql -u roo
This will start the mysql client and prompt:
mysql>

4: Setup new MySQL password for root:
First use the database mysql.
mysql> use mysql;

and fire the query to change the password for the root.
mysql> update user set password=PASSWORD("NEW PASSWORD") where User='root';

After that flush the privileges by following command.
mysql> flush privileges;

5: Quit and Stop MySQL Server:
#mysql>quit

# /etc/init.d/mysql stop

That's it !! you are done.

Start MySQL server and login with new password

# /etc/init.d/mysql start
# mysql -u root -p

No comments: