1. Change the password in the case of knowing the MySQL password
mysqladmin Command (headings)
The format is as follows (where user is the username and password is the new password):
mysqladmin-u user-p Password Password
After this command, you will be prompted to enter your original password, and you can modify it after entering it correctly.
UPDATE User statement (headings record)
This must be done first by logging in to MySQL with the root account and then executing:
UPDATE user SET Password=password (' 123456 ') WHERE user= ' root ';
FLUSH privileges;
SET PASSWORD statement (headings record)
This approach also requires that you log in to MySQL with the root command and then execute:
SET PASSWORD for Root=password (' 123456 ');
2. Change password in case of forgotten MySQL password
Modify the configuration file/etc/my.cnf, add the following parameters under the Mysqld segment, and then restart MySQL
Skip-grant-tables
Login MySQL without a password at this time,
UPDATE user SET Password=password (' 123456 ') WHERE user= ' root ';
FLUSH privileges;
SET PASSWORD statement (headings record)
This approach also requires that you log in to MySQL with the root command and then execute:
SET PASSWORD for Root=password (' 123456 ');
Again in the configuration file to remove the added parameter, restart MySQL can
This article from "Martin" blog, declined reprint!
MySQL Password modification