Reset the MySQL password:
Stop the MySQL service and start it with the skip-grant-tables parameter.
Service mysqld stop;
Mysqld_safe -- skip-grant-tables -- user = mysql &
In this case, you can access the MySQL command line without authorization.
Mysql> UPDATE mysql. user SET Password = PASSWORD ('...') WHERE User = '...' AND Host = '...'; flush privileges;
The above operations still have some flaws:
Anyone can connect to MySQL during the password reset period (unless the database server shields Internet access );
Recommended Methods:
Shell> service mysqld stop;
// UPDATE mysql. user SET Password = PASSWORD ('... ') WHERE User = '... 'AND Host = '... '; flush privileges; this SQL statement is written to a directory that mysql has permission to read;
Mysql> mysqld_safe -- init-file =/path/to/init/file -- user = mysql &
// Delete the file to avoid password leakage;
Avoid restarting MySQL twice !!!
It is worth mentioning that in MySQL5.6, use mysql_config_editor to encrypt. mylogin. cnf to log on. As long as the file exists, you do not need to consider losing the password!