How to change the password after MySQL forgets it

Time:2021-7-22

Often, someone will forget their MySQL password. Here is a way to log in to MySQL without password and change the password

Step 1:
Enter services.msc from the run window
How to change the password after MySQL forgets it

Step 2:
Enter the service interface, find MySQL and right-click to stop
How to change the password after MySQL forgets it

Step 3:
Open the MySQL installation path (if you forget the installation path, you can right-click the properties in the service to view it)
How to change the password after MySQL forgets it

Open the bin directory
How to change the password after MySQL forgets it

Step 4:
Copy the path to the CMD window and press enter
How to change the password after MySQL forgets it

inputmysqld –skip-grant-tablesCommand. If there is no mysqld in the bin directory, check whether there is mysqld NT. If there is only MySQL NT, enter this commandmysqld-nt –skip-grant-tables
How to change the password after MySQL forgets it

At this time, the command window will enter a state that cannot be input, and a new CMD window will be opened

Step 5:
Enter MySQL in the new CMD window and press enter
How to change the password after MySQL forgets it
We will find that we can directly access the MySQL database, and then we can change the password

Enter MySQL database with command
How to change the password after MySQL forgets it

inputselect user,host,password from user;
How to change the password after MySQL forgets it

Execute update password statement
update user set password=password(‘123456′) where user=’root’ and host=’localhost’;
‘123456’ is the password you want to change

Step 6:
At this time, the password is changed, and you can log in to MySQL happily
Don’t forget to open MySQL from the service~