Original: https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html
1. Stop the MySQL service, if MySQL is installed in the Windows service, stop in Service Manager, and if it is running on the command line, you will need to force the process to stop in Task Manager.
2. Create a script to start MySQL load execution when the script content is to change the root password:
MySQL 5.7.6 and later versions:
ALTER USER ' root ' @ ' localhost ' identified by ' mynewpass ';
MySQL 5.7.5 and Previous versions:
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Mynewpass ');
将文件保存在某路径,例如D:/init.sql
3. 需要进入到mysql的安装目录下的bin目录,其中包含了mysql的daemon程序“mysqld.exe”,在这个目录运行命令行(文件管理器shift+鼠标右键-在此处打开命令行窗口),输入命令:
Mysqld--init-file=d:/init.sql
Ensure that the MySQL service starts properly by looking in the process manager for a process that has no MySQL, if the path of the script is specified incorrectly, or if there is a problem in the script that causes the startup to fail. If successful startup, the root password should be modified.
If alter user modifies the password statement to fail, attempt to modify the user table directly using the following statement:
UPDATE mysql.user SET authentication_string = PASSWORD (' Mynewpass '), password_expired = ' N ' WHERE user = ' root ' and Host = ' localhost '; FLUSH privileges;
4. After completion, start the MySQL service using normal boot mode, no longer use the--init-file parameter
MYSQL 5.7 for Windows reset root password