There are many ways to change the root password. below I will summarize some common methods for changing the root password for MySQL data. if you need to know or forget the root password, you can refer to it.
Method 1, Using mysqladmin
The following two commands are used: mysqladmin.exeand mysql.exe. the command format for changing the password of mysqladmin is as follows:
mysqladmin -u root -p[oldpass] password newpass
Note that oldpass (old password) is optional. if the default root password is blank, you do not need to enter it. if you need to change the old password, note that there is no space between the old password and-p, otherwise, an error is reported. In addition, the password and newpass are separated by spaces.
mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
Method 2: In the DOS mode (the serial mode is positioned to the mysqlinstallation directory and in the sub-directory, and mysql.exe is used to enter, that is
C:Program FilesMySQLMySQL Server 5.1bin>mysql -u root -pEnter password: ******
Use the mysqladmin.exe command to modify the Mysql root password
Generally, the default Mysql root password is blank. if you have not set the root password before, use the mysqladmin command. you can use the following mysqladmin command to change the root password:
C:Program FilesMySQLMySQL Server 5.1bin>mysqladmin -u root -p password 123456Enter password:C:Program FilesMySQLMySQL Server 5.1bin>mysql -u root -p123456
As mentioned above, when mysqladmin is used to change the default password of root for the first time, Enter passwordto Enter the Mysql command line. Then, use the mysql.exe command to Enter the root and password.
If the root user has set a password, use the following method:
mysqladmin -u root password oldpass "newpass"
Method 3:Use UPDATE to directly edit the user table
mysql -u rootmysql> use mysql;mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';mysql> FLUSH PRIVILEGES;
When the root password is lost
mysqld_safe --skip-grant-tables&mysql -u root mysqlmysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';mysql> FLUSH PRIVILEGES;
It is very convenient to use phpmyadmin to change the Mysql root password. after installing and configuring phpmyadmin, first log on to the management interface, click the Change Password link on the right, and enter the new Mysql root password you want to modify, click execute.