Friday, November 2, 2012

Reset Lost/Forgotten root password for MySQL

The following are the steos to restore MySQL root password that is lost/forgotten.

Step 1: Stop MySQL daemon if it is currently running    
     Command to find the MySQL Pid and kill the MySQL process
                ps –ax|grep mysql
                kill -9 pid
Step 2: Run MySQL safe daemon with skipping grant tables
                 mysqld_safe --skip-grant-tables & 
Step 3: Login to MySQL as root with no password
                 mysql -u root mysql
Step 4: Run UPDATE query to reset the root password
          UPDATE user SET password=PASSWORD("ualue=42") WHERE user="root";
      FLUSH PRIVILEGES; 
Step 5: Stop MySQL safe daemon
         Command to find the MySQL safe daemon Pid and kill the MySQL process
               ps –ax|grep mysqld_safe
               kill -9 pid
Step 6: Start MySQL
                            /etc/init.d/mysql start
Step 7: Login into MySQL using root password                          
                           mysql -uroot -proot