You can recover MySQL root user password with following steps:

  1. Login to your linux machine as a root user
  2. Stop MySQL by executing the following command:

    # service mysqld stop

  3. Now, Start MySQL with --skip-grant-tables option. This command will skip the prompt for password.

    # mysqld_safe --skip-grant-tables &
  4. Login to MySQL server as a root user.

    # mysql -u root

  5. Now, you can set the new MySQL root password by executing following commands.

    mysql> use mysql;

    mysql> update user set password=PASSWORD("PASSWORD") where user='root';
    mysql> flush privileges;
    mysql> quit

  6. Exit from MySQL and restart MySQL process.

    # service mysqld stop

  7. Start MySQL normally and test the new root user password.

    # service mysqld start
    # mysql -u root -p