-
Log on to your system as Administrator.
-
Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
If your server is not running as a service, you may need to use the Task Manager to force it to stop.
-
Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
-
Save the file. This example assumes that you name the file
C:\mysql-init.txt
. -
Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
-
Start the MySQL server with the special
--init-file
option (notice that the backslash in the option value is doubled):C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
C:\> mysqld --init-file=C:\\mysql-init.txt
- 删除
C:\\mysql-init.txt