Method one, with Mysqladmin
Here you use the two commands that come with MySQL Mysqladmin.exe and mysql.exe,mysqladmin the command format to modify the password is as follows
The code is as follows |
Copy Code |
Mysqladmin-u Root-p[oldpass] Password newpass |
Note Oldpass (old password) optional, if the root default password is empty, you do not need to enter, if you need to change the old password, please note that the old password and-p between the space, otherwise it will error, and password and newpass (new password) between the space separated.
The code is as follows |
Copy Code |
Mysql-u Root mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Newpass '); |
Mode two: In DOS mode (CMD mode) to navigate to the MySQL installation directory in the subdirectory bin, call Mysql.exe Enter, that is
The code is as follows |
Copy Code |
C:Program filesmysqlmysql Server 5.1bin>mysql-u root-p Enter Password: Hu Jintao |
Use the Mysqladmin.exe command to modify the MySQL root password
The general MySQL root default password is null, if you have not previously set the root password to use the Mysqladmin command, you can use the following mysqladmin command to modify the root password
The code is as follows |
Copy Code |
C:Program filesmysqlmysql Server 5.1bin>mysqladmin-u root-p password 123456 Enter Password: C:Program filesmysqlmysql Server 5.1bin>mysql-u root-p123456 |
As mentioned earlier, when using mysqladmin to first modify the default password for root, enter password enter, and then use the Mysql.exe command to type root and its password to enter the MySQL command line.
If Root has already set the password, use the following method
The code is as follows |
Copy Code |
mysqladmin-u root password Oldpass "Newpass" |
Method 3: Edit the user table directly with update
The code is as follows |
Copy Code |
Mysql-u Root mysql> use MySQL; mysql> UPDATE user SET Password = Password (' newpass ') WHERE user = ' root '; mysql> FLUSH privileges; |
When you lose the root password, you can do this.
The code is as follows |
Copy Code |
Mysqld_safe--skip-grant-tables& Mysql-u Root MySQL mysql> UPDATE user SET Password=password ("New password") WHERE user= ' root '; mysql> FLUSH privileges; |
Use phpMyAdmin to change the MySQL root password is very convenient, installation configuration good phpmyadmin, first login admin interface, click on the right to modify the password link, enter you want to modify the MySQL root new password, the last click to execute can