How to modify the mysql database when the password is forgotten (take the local wamp environment as an example)

1. Open the folder where mysql.exe and mysqld.exe are located, and copy the path address (/usr/local/mysql/bin under linux)

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. At this time, the user authentication of mysql is skipped. Note that the command line cannot be operated after entering this command, and a new command line can be opened at this time. Note: Before entering this command, end the mysqld.exe process in the task manager to ensure that the mysql server has ended. (Linux can add skip-grant-tables under the [mysqld] entry in the /etc/my.cnf file (do not use the authorization table when logging in), save it, and restart mysql)

4. Then directly enter mysql, you can log in to the database without any login parameters and press Enter directly.

5. Enter show databases; you can see all databases indicating successful login.

6. The mysql library is where the username is saved. Type use mysql; select the mysql database.

7.show tables To view all tables, you will find a user table, which stores account information such as username, password, permissions and so on.

8. Enter select user,host,password from user; to view account information.

9. Change the root password, 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 the new password.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325651337&siteId=291194637