Friday, August 19, 2011

MySql Forgot Password

If you know the password then it is very easy for you to reset the MySql Password but what if you do not remember the password and want to reset it.

To figure it out I spent almost 2 days and now I am sharing so that same thing does not happen with you.

Now, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.

First of all you will need to ensure that your database is stopped:
root@ravi: /etc/init.d/mysql stop

Now you should start up the database in the background, via the mysqld_safe command:
root@ravi:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6702
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started
Here you can see the new job (number "1") has started and the server is running with the process ID (PID) of 6702.

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

root@ravi:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';

Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.02 sec)

mysql> exit

Bye

Hope this save your time :)

0 comments:

Post a Comment