Recover the root password

Due to the way MySQL encrypts passwords it is not possible to recover one, There is however a way of resetting one. Here is how to do it for the root user…

at a command prompt type…

  1. sudo service mysqld stop
  2. sudo mysqld_safe --skip-grant-tables &
  3. sudo mysql
    then in MySQL
  4. UPDATE mysql.user SET password=PASSWORD('new-password') WHERE user='root';
  5. FLUSH PRIVILEGES;
  6. EXIT;
  7. mysqladmin -u root -p shutdown
    You will be asked for the root password that you have just set
  8. sudo service mysqld start

That's all folks!