Reset the password of the root user in the MySQL database. if you have never set the root user password for MySQL, the server does not need the password for connection as the root user. However, we recommend that you set a password for each account.
If you have previously set the root user password but forgot the password, you can set a new password. The following steps are applicable to Windows. This section introduces the steps for the Unix platform.
On Windows, this step is:
Log on to the system as a system administrator.
If the MySQL server is running, stop it. For a server running as a Windows service, go to the service manager:
Choose Start> Control Panel> Management Tools> services
Find the MySQL server in the list and stop it.
If the server is not running as a service, you may need to use the Task Manager to force it to stop.
Create a text file and place the following command in a single line:
Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');
Save the file with any name. In this example, the file is C: mysql-init.txt.
Open the console window and enter the doscommand prompt:
Start menu-> Run-> cmd
Suppose you have installed MySQL to C: mysql. If you install MySQL in another location, adjust the following commands.
Run the following command at the doscommand prompt:
C:> C: mysqlinmysqld-nt -- init-file = C: mysql-init.txt
When the server is started, execute the content of the file named by the "-- init-file" option to change the root user password. C: mysql-init.txt should be deleted when the server is successfully started.
If you use the MySQL installation wizard to install MySQL, you may need to specify the "-- defaults-file" option:
C:> C: Program FilesMySQLMySQL Server 5.1inmysqld-nt.exe
-- Defaults-file = "C: Program FilesMySQLMySQL Server 5.1my.ini"
-- Init-file = C: mysql-init.txt
Use the service manager to find the appropriate "-- defaults-file" settings:
Choose Start> Control Panel> Management Tools> services
Find the MySQL service in the list, right-click it, and select the "attribute" option. Include the "-- defaults-file" setting in the Path of the executable field.
Stop the MySQL server and restart it in normal mode. If you run the server as a service, you should start it from the Windows service window. If the server is started manually, the command can be used as usual.