Home  >  Article  >  Database  >  How Do I Reset My Lost MySQL Root Password on WAMP?

How Do I Reset My Lost MySQL Root Password on WAMP?

Barbara Streisand
Barbara StreisandOriginal
2024-11-16 18:15:03862browse

How Do I Reset My Lost MySQL Root Password on WAMP?

Regaining Access to Lost MySQL Password on WAMP: A Step-by-Step Guide

Losing access to your MySQL password can be a daunting experience, especially when working with PHPMyAdmin on WAMP. However, there's a relatively simple solution that allows you to reset your root password and regain control.

Steps to Reset Root Password:

  1. Stop MySQL Service: Navigate to WAMPManager, select MySQL, and stop the service.
  2. Edit my.ini File: Go to MySQL in WAMPManager and open the my.ini file.
  3. Add skip-grant-tables: Locate the [wampmysqld] section and add the line "skip-grant-tables" directly after it.
  4. Restart MySQL Service: Resume the MySQL service in WAMPManager.
  5. Open MySQL Console: Click on MySQL Console in WAMPManager.
  6. Reset Password: Execute the following commands (with semicolons):

    Pre-MySQL 5.7:

    • UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    • FLUSH PRIVILEGES;

    Post-MySQL 5.7:

    • UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
    • FLUSH PRIVILEGES;
  7. Exit MySQL: Type "quit" and press ENTER to exit the console.
  8. Stop MySQL Service: Stop the MySQL service in WAMPManager again.
  9. Edit my.ini File: Remove the skip-grant-tables parameter you added earlier.
  10. Restart MySQL Service: Resume the MySQL service in WAMPManager.

Additional Considerations:

  • You may encounter an error if your my.ini file is read-only. In that case, make sure you have administrator privileges and change the file's properties to writable.
  • The new password can be anything you want.
  • If you want to prevent the root password from expiring automatically, you can run the following query in MySQL Console:

    • ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

Once you complete these steps, you should be able to log into PHPMyAdmin using the 'root' user with your newly set password.

The above is the detailed content of How Do I Reset My Lost MySQL Root Password on WAMP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn