Thursday, September 9, 2010

Reset root password for phpmyadmin/mysql

I recently faced an issue where I forgot the root password for mysql and ended up searching for simple procedure to unlock it by resetting the password. So I want to save here the steps to unlock the phpmyadmin if I should loose my root password again. Then I can skip the searching-for-an-hour part and go straight to the unlocking part. (Thanks to fredanthony and for source thread: click here)

The error message you get when you enter wrong password in the login page is :
"#1045 - Access denied for user 'root'@'localhost' (using password: NO) "

Steps:

  1. Stop mysql - $ /etc/init.d/mysql stop
  2. Kill all mysql related processes. The ps list can be pretty big and confusing so better use grep to filter mysql processes and use only those pids in kill command. - $ ps waux | grep mysql, $kill -9 pids
  3. Open a new session of mysql by skipping permissions - $ /usr/bin/mysqld_safe --skip-grant-tables
  4. While the above session is open, in a new tab open a new session of mysql - $ /usr/bin/mysql
  5. Inside the new session,change the database - (inside mysql)$use mysql;
  6. The critical part of our unlocking process is resetting the password for root user -(inside mysql) $UPDATE user SET Password=PASSWORD('YOUR_PASSWORD_HERE')
    WHERE Host='localhost' AND User='root'; - This step sets new password for the root user.
  7. Then quit the mysql sessions and restart the mysql - $quit, $/etc/init.d/mysql restart
  8. try logging into phpmyadmin with new password you set in update command and viola!

P.S: List of useful SQL command syntax - source

METHOD 2:
This step is to change the MYSQL root password. Source: Ubuntu help documentation. In a terminal enter the following command:

"sudo dpkg-reconfigure mysql-server-5.1"

However verify you have mysql-server-5.1 in your system. To find that, in terminal type "mysql -V". The result would print out details about the mysql server installed in your system.Sample result was
"mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1". Hence I use 5.1 in the above command. When you run the reconfigure command, it will prompt you to enter password and restarts the mysql daemon.

No comments: