How to Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables.

How to Recover a MySQL root password. Stop the MySQL server process.

Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server

# /etc/init.d/mysql stop

# mysqld_safe –skip-grant-tables &

# mysql -u root

mysql> use mysql;

mysql> update user set password=PASSWORD(“newrootpassword”) where User=’root’;

mysql> flush privileges;

mysql> quit

# /etc/init.d/mysql stop

# /etc/init.d/mysql start

Yes, the steps you provided are generally correct for recovering a MySQL root password. Here’s a more detailed explanation of each step:

  1. Stop the MySQL server process:
    • On Linux systems: sudo service mysql stop
    • On Windows: Use the Services application to stop the MySQL service.
  2. Start again with no grant tables:
    • On Linux, you can start MySQL with the --skip-grant-tables option: sudo mysqld --skip-grant-tables &
    • On Windows, you might need to edit the MySQL configuration file to include skip-grant-tables under the [mysqld] section, and then restart the MySQL service.
  3. Login to MySQL as root:
    • Open a new terminal or command prompt and connect to MySQL without a password: mysql -u root
  4. Set a new password:
    • Once you are logged into MySQL, change the root password using the following SQL command:
      sql
      UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
      FLUSH PRIVILEGES;

    Replace 'new_password' with your desired password.

  5. Exit MySQL:
    • Type exit and press Enter to exit the MySQL shell.
  6. Restart the MySQL server:
    • On Linux: sudo service mysql start
    • On Windows: Use the Services application to start the MySQL service.

Remember to replace placeholders like 'new_password' with your actual values. After these steps, you should be able to log in to MySQL with the new root password.