When we forget the mysql database password, we cannot enter the database normally and cannot change the password. So how to change the password at this time? Here is a simple and commonly used way to change the password.
1. Open the folder where mysql.exe and mysqld.exe are located, copy the path address
2. Open the cmd command prompt and enter the folder where mysql.exe is located in the previous step.
3. Enter the command mysqld --skip-grant-tables and press Enter. MySQL will be skipped at this time. User Authentication. Note that the command line cannot be operated after entering this command. At this time, you can open a new command line. Note: Before entering this command, end the mysqld.exe process in the task manager to ensure that the mysql server has ended.
4. Then enter mysql directly without any login parameters and press Enter to log in to the database.
5. Enter show databases; You can see all databases indicating successful login.
6. The mysql library is where the user name is saved. Enter use mysql; to select the mysql database.
7.show tables View all tables, you will find that there is a user table, where the user name and password are stored , permissions and other account information.
8. Enter select user,host,password from user; to view account information.
##9. Change the root password and enter
update user set password=password('123456') where user='root' and host='localhost';
10. Check the account information again, select user,host,password from user; You can see that the password has been modified.
11. Exit the command line, restart the mysql database, and try to log in with a new password.
12. Tested to log in to mysql without a password and found that I could still log in, but when displaying the database, I could only see two databases. Explain. Skipping password verification after reboot has been eliminated.
13. The reason why I can still log in without a password after restarting the database is because there is an account in my database that does not require a password. .
NotePay attention to several places where you need to restart the databaseThe above is the detailed content of How to modify the MySQL database password when it is forgotten?. For more information, please follow other related articles on the PHP Chinese website!