Home  >  Article  >  Database  >  How to Retrieve Lost MySQL Credentials?

How to Retrieve Lost MySQL Credentials?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-20 15:36:12629browse

How to Retrieve Lost MySQL Credentials?

Retrieving Lost MySQL Credentials

If you've misplaced your MySQL username and password, don't despair. This guide offers a step-by-step solution to retrieve them.

Instructions:

  1. Stop the MySQL Process:

    • Navigate to your MySQL installation directory and execute the following command:

      sudo /etc/init.d/mysql stop
      • Remember to substitute '/etc/init.d/mysql' with the correct path to your MySQL installation on Linux or 'net stop MySQL' on Windows.
  2. Restart MySQL with --skip-grant-tables:

    • Start MySQL using the '--skip-grant-tables' option to bypass password authentication:

      sudo /etc/init.d/mysql start --skip-grant-tables
  3. Connect as Root User:

    • Launch the MySQL console client with the '-u root' option to establish a connection as the root user:

      mysql -u root
  4. List MySQL Users:

    • Display all available users within the MySQL database:

      SELECT * FROM mysql.user;
  5. Reset Password:

    • Assign a new password to the desired username:

      UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
      • Replace '[password]' with your preferred password and '[username]' with the username you want to modify.
  6. Restore Normal Operation:

    • Once you have reset the password, terminate the MySQL process again:

      sudo /etc/init.d/mysql stop
      • Finally, restart MySQL normally without '--skip-grant-tables' to ensure proper security:

        sudo /etc/init.d/mysql start

Caution:

Always remember to restore normal MySQL operation by stopping and then restarting the process normally after completing these steps. Leaving '--skip-grant-tables' enabled can compromise your database's security.

The above is the detailed content of How to Retrieve Lost MySQL Credentials?. 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