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:
Stop the MySQL Process:
Navigate to your MySQL installation directory and execute the following command:
sudo /etc/init.d/mysql stop
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
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
List MySQL Users:
Display all available users within the MySQL database:
SELECT * FROM mysql.user;
Reset Password:
Assign a new password to the desired username:
UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
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!