I. MySQL password recovery method one
It is possible that your system does not have SAFE_MYSQLD programs (such as the Ubuntu OS I am using now, Apt-get installed MySQL),
The following method can recover 1. Stop mysqld;/etc/init.d/mysql stop (you may have other methods, stop mysqld running anyway)
2. Start MySQL with the following command to start without checking permissions;
Mysqld--skip-grant-tables & or Mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
3. Then log in to MySQL using the root user with a blank password; mysql-u root MySQL
4. Change the password of the root user;
mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root ' and host= ' root ' or host= ' locahost ';
mysql> flush Privileges;
Mysql> quit restart
Mysql/etc/init.d/mysql restart
#mysql-uroot-p
You can log in with the new password newpassword.
Two. MySQL password recovery method Two If you forget the root password of MySQL, you can reset it in the following ways:
1. Kill the MySQL process in the system; Killall-term mysqld
2. Start MySQL with the following command, starting without checking permissions; Safe_mysqld--skip-grant-tables &
3. Then log in to MySQL using the root user with a blank password; mysql-u root
4. Change the password of the root user;
mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root ';
mysql> flush Privileges;
Mysql> quit to restart MySQL,
#mysql-uroot-p
You can log in with the new password.
Solutions for forgetting the MySQL root password