Method One: Use the Set password command
First, log in to MySQL
Mysql-uroot-p
Then execute the Set password command
Set password for [email protected] = password (' 654321 ');
In the example above, change the root password to 654321
Method Two: Use Mysqladmin
Format: Mysqladmin-u username-P Old password password new password
mysqladmin-uroot-p123456 password "654321"
In the example above, change the root password from 123456 to 654321
Method Three: Change the user table for MySQL
First, log in to MySQL
Mysql-uroot-p
Then manipulate the user table of the MySQL library to update
mysql> use mysql;mysql> Update user set Password=password (' 654321 ') where user= ' root ' and host= ' localhost '; mysql& Gt Flush privileges;
Method Four: In case of forgetting the password
First stop the MySQL service
Service Mysqld Stop
Start MySQL in a way that bypasses authorization
Mysqld_safe--skip-grant-tables &
Log in as root user MySQL
Mysql-u Root
Manipulate the user table of the MySQL library to update
mysql> use mysql;mysql> Update user set Password=password (' 654321 ') where user= ' root ' and host= ' localhost '; mysql& Gt Flush Privileges;mysql> Quit
Restart MySQL Service
Service mysqld Restart
MySQL change root password under Linux