mysql small note: what to do if mysql forgets the password?

I have a deep understanding of this problem, so let's move directly to the topic.
Name in advance: I am above mysql version 8.0 and
all the following operations are opened by the administrator cmd

1. Prerequisite

1. First judge whether the mysqld service exists in the file, run the following command, if no error is reported, you can jump directly tostep

Insert picture description here

2. If you report an error, please follow the procedure below to configure

Insert picture description here


Insert picture description here


and then execute mysqld. If no error is reported, it is ok.

Second, the steps

1. Turn off the mysql service

net stop mysql80

2. Since we have forgotten the password now, but we still have root privileges, we can set the login privileges through mysqld ===>root can skip the password verification and directly enter the database

mysqld --console --skip-grant-tables --shared-memory
Insert picture description here


At this time, the cursor keeps flashing, and it feels like the card owner, don’t panic, this is the normal execution is successful, we open a new terminal cmd (administrator open)

3. Run the following command to directly enter mysql

Insert picture description here


4, and then set the new password of the current root user to 123

set password for [email protected] = '123';

5. Run exit to exit the above mysql and restart the mysql service

net start mysql80

6. Log in again

mysql -uroot -p123

You can log in successfully