Recovering MySQL Username and Password
Losing your MySQL username and password can be a daunting experience, but it's not an insurmountable one. Here's a step-by-step guide to retrieve them:
Steps:
-
Stop the MySQL Process:
- Use the service command or kill the process using kill -9 command.
-
Start MySQL with Skip-Grant-Tables Option:
- Add the --skip-grant-tables flag when starting MySQL. This will temporarily disable the user verification.
-
Start MySQL Console as Root:
- Execute mysql -u root -p to open the MySQL console as the root user.
-
List MySQL Users:
- Run the SELECT * FROM mysql.user; query to display all users.
-
Reset Password:
- Use the UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]'; query to reset the password for the desired user.
-
Exit MySQL Console:
- Type exit to exit the MySQL console.
-
Restart MySQL Normally:
- Remove the --skip-grant-tables option when starting MySQL to re-enable user verification.
-
Test the New Password:
- Use the mysql -u [username] -p command to log in using your recovered username and password.
Caution:
- Remember to disable the --skip-grant-tables option after resetting the password to maintain the security of your database.
- It's recommended to create a strong password for the root user and keep it secure.
- Consider using a password manager to securely store your login credentials.
The above is the detailed content of How Do I Recover a Lost MySQL Username and Password?. 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