I forgot my mysql password. After searching online for a long time, I finally found something that works.
1. Terminate the MySql service
Right-click-Manage-Service-MySql-Stop service
or
Open cmd as administrator and execute:
net stop mysql
2. Skip password entry for authorization
mysqld --console --skip-grant-tables --shared-memory
3. Re-open a cmd window (don’t close the previous cmd window), reset the password, and execute:
mysql -uroot -p
At this time, the password has been bypassed to log in to mysql.
Change the password and set it to blank
UPDATE mysql.user SET authentication_string='' WHERE user='root';
4. Close all command line interfaces, open the MySql service normally and then log in (when a data password is required, just press Enter)
use mysql
#Set the password to 123456
ALTER user root@'localhost' identified by '123456';
or can
Set encryption rules and update new password and authorization (directly copy these SQL statements and your password will be updated to 123456)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
alter user 'root'@'localhost' identified by '123456';
grant all privileges on *.* to "root"@'localhost';
flush privileges;
5. The password is set successfully, restart mysql and log in with the new password.
net start mysql