If you have forgotten or lost your MySQL root password you can still recover it. In order to reset your MySQL root password, you’ll need to have root access to the server. If you don’t, you probably shouldn’t have root access to MySQL either. :)

Reset MySQL Root Password

  1. Login as root to your server/machine/box

  2. Stop your current MySQL daemon (/etc/init.d/mysql stop)

  3. Enter

    mysqld_safe --skip-grant-tables

    This will load MySQL daemon without checking for authorization against the Grant Tables. You’ll be allowed to do whatever you need as root, including resetting the password.

  4. Type

    mysql --user=root mysql

    This will log you into MySQL as the user root using the table “mysql” – where grant tables are stored.

  5. And then

    UPDATE USER SET Password=PASSWORD('your-password') WHERE  USER='root';
    FLUSH privileges;
    exit;

    Replace your-password above with whatever password you would like to reset root MySQL to.

  6. Restart mysql (usually /etc/init.d/mysql restart)

  7. Login again using your new root password

    mysql -u root -p
    Enter Password: