If you have never set a root password for MySQL, the server does not require a password when connecting as root. However, it is recommended 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 for the Windows platform. The rest of this section covers the steps for the Unix platform.
On the Windows platform, this step is:
Log in to the system as an administrator.
Stop the MySQL server if it is running. For a server running as a Windows service, go to Service Manager:
Start Menu -> Control Panel -> Administrative Tools -> Services
Then locate the MySQL server in the list and stop it.
If the server is not running as a service, it may be necessary to use 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 case, the file is C: mysql-init.txt.
Open the console window, enter the DOS command prompt:
Start menu -> Run -> cmd
Suppose you have installed MySQL to C: mysql. If you installed MySQL to another location, make the appropriate adjustments to the following commands.
At the DOS command prompt, execute the command:
C:> C: mysqlbinmysqld-nt -init-file =
C: mysql-init.txt
At server startup, execute the file named by the "-init-file" option and change the root password. When the server starts successfully, you should delete C: mysql-init.txt.
If you installed MySQL using the MySQL installation wizard, you may need to specify the "-defaults-file" option:
C:> C: Program FilesMySQLMySQL Server 5.1binmysqld-nt.exe
-defaults-file = "C: Program FilesMySQLMySQL Server 5.1my.ini"
-init-file = C: mysql-init.txt
Use Service Manager to find the appropriate "-defaults-file" setting:
Start Menu -> Control Panel -> Administrative Tools -> Services
Find the MySQL service in the list, right-click, and select the "Properties" option. The "-defaults-file" setting is included in the Path of the executable field.
Stop the MySQL server and restart it in normal mode. If you are running the server as a service, start it from the Windows Services window. If you start the server manually, you can use commands as you normally would.