Sometimes the root password of mysql is easy to forget. At this time, you can change the password by entering the safe mode of mysql – skip-gratn-tables. The steps are as follows:
1) Enter the bin directory of mysql
cd D:\DBtools\mysql5_7_31_winx64\bin
2) Use the administrator to open a CMD black box and enter the following command to close the mysql service
net stop mysql
3) Enter mysql safe mode
mysqld -nt --skip-grant-tables
4) Open a CMD black box with administrator privileges, and enter the following commands in sequence:
mysql -uroot -p
Enter password: 此项不用填,直接回车
use mysql;
update mysql.user set authentication_string=password('你的密码') where host='localhost' and user='root';
flush privileges;
exit
5) Open the mysql database service, and use alter to update the password, and enter the following commands in sequence:
net start mysql
mysql -uroot -p
Enter password: 你的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
exit