The method of forgetting password modification for MySQL under Centos
A few days ago, I installed a MySQL 5.7 on the virtual host and configured a password. Today, I forgot it directly (embarrassed face). So I thought about posting this password modification method in case my friend forgot his password.
Start by closing MySQL:
service mysqld stop
Set MySQL login method to login without password:
mysql_safe --user=mysql --skip-grant-tables -skip-networking &
After that, you can directly use mysql -u root to log in to the database ~ After logging in to the database, you can modify and set the new password in the original data table. The code is as follows:
use mysql;UPDATE userSET Password=PASSWORD('NEWPASSWORD')where user='root';FLUSH PRIVILEGES;quit;
Replace NEWPASSWORD in the above code with the new password you want to set."FLUSH PRIVILEGES" is used to refresh the system permissions table to make the changes effective. Of course, you can also restart MySQL server directly to make the settings effective.