For people who often forget their passwords, password retrieval or password reset should be very important.
mysql provides a way to reset the root password, which is relatively simple and recorded here:
Idea: Add parameters when mysql starts, so that it reads the initialization file, and sets a new password in the initialization file.
Steps (Windows system):
1. Log in to the system as an administrator
2. Stop the MysqlServer service
3. Create a text file and add a line to the file to reset the password
For example, (mysql 5.7.6 and later)
alert user 'root'@'localhost' identified by 'MyNewPass';
mysql 5.7.5 and earlier:
set password for 'root'@'localhost' = password('MyNewPass')
4. Save the file, such as c:\mysql-init.txt
5. Open the cmd window
6. Run the following command to start mysqlserver
D:\mysql-5.6.22-winx64\bin>mysqld --init-file=c:\\mysql-init.txt
2016-05-09 11:16:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is depreca
ted. Please use --explicit_defaults_for_timestamp server option (see documentati
on for more details).
After the startup is successful, delete the mysql-init.txt file.
Refer to the mysql documentation
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html