If you have never set a root user password for MySQL, the server does not need a 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
Assume that 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: \ mysql \ bin \ mysqld-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. When the server is successfully started, delete the C: \ mysql-init.txt.
If you use the MySQL Installation Wizard to install MySQL, you may need to specify the "-- defaults-file" option:
C: \> C: \ Program Files \ MySQL Server 5.1 \ bin \ mysqld-nt.exe
-- Defaults-file = "C: \ Program Files \ MySQL Server 5.1 \ my. 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.
The new password should be used for connection.