Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of forgetting password modification for MySQL under Centos

Shulou Source: shulou.com Published: 2022-06-01 08:31:24 10月02日 Update

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.

Tags: Password login data code database way to make new secret original awkward upload host datasheet server permissions system virtual host first backup service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Apple MariaDB Shulou Technology