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
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
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
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: mysqlbinmysqld-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.1binmysqld-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. 2 pages in total.
The new password should be used for connection.
To reset the root user password in a Unix environment, follow these steps:
Log on to the system as a Unix root user or as a running mysqld server.
Find the. pid file that contains the server process ID. The exact location and name of the file depends on your distribution, host name, and configuration. Common locations are/var/lib/mysql/,/var/run/mysqld/, and/usr/local/mysql/data /. Generally, the file name extension is. pid and starts with mysqld or the host name of the system.
Use the path name of the. pid file in the following command to send a normal kill (instead of kill-9) to the mysqld process to stop the MySQL server:
Shell> kill 'cat/mysql-data-directory/host_name.pid'
Note that the cat command uses the symbol "'" instead of "'": this will make cat output into the kill command.
Create a text file and place the following commands on one line in the file:
Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');
Save the file with any name. In this example, the file is ~ /Mysql-init.
Use special "-- init-file = ~ /Mysql-init "option to restart the MySQL server:
Shell> mysqld_safe -- init-file = ~ /Mysql-init &
The content of the file init-file is executed when the server is started and the root user password is changed. After the server is successfully started, delete it ~ /Mysql-init.
The new password should be used for connection.
As an optional method, you can use the mysql client to set a new password on any platform (but this method is not secure enough ):
Stop mysqld and restart it with the "-- skip-grant-tables -- user = root" option (Windows users can omit -- user = root ).
Use the following command to connect to the mysqld Server:
Shell> mysql-u root
Run the following statement on the mysql client:
Mysql> UPDATE mysql. user SET Password = PASSWORD ('newpwd ')
-> WHERE User = 'root ';
Mysql> flush privileges;
Replace "newpwd" with the actual root user password you intend to use ".
The new password should be used for connection.