Get the App
SLTechnology News&Howtos  ›  Database  › 

Delete the user in mysql by mistake, how to reset the root account and password

Shulou Source: shulou.com Published: 2022-06-01 03:23:58 10月02日 Update

When practicing the mysql statement, you use delete to delete all users in the database, including root users. And carried out the flush privileges; at this time found that re-login mysql has been unable to log in normally. For this, we need to reset the root account and root password. The specific steps are as follows:

Delete user actions:

Mysql > delete frommysql.user; Delete all users mysql > flushprivileges

First of all, break all the links associated with the database to prevent the loss of data when the database is restarted.

[root@node1 ~] # service mysqld stop

Modify database configuration file

[root@node1 ~] # vim / etc/my.cnf

The contents under [mysql] in the configuration file

In [mysql]

Add "skip-grant-tables" to the next line

Save and exit, restart the mysql database

[root@node1mysql] # mysqlmysql > insertinto mysql.user (host, user, password,sll_cipher,x509_issuer,x509_subjec) values ('localhost',' root',password ('123456'),',')

Exit the database, make changes to the mysql.cnf configuration file, and delete the newly added lines. Just restart the database.

[root@node1 ~] # service mysqld restart

You can complete the addition of mysqlroot users!

The second way is not to modify the configuration file of mysql.

Service mysqld stop / / stop mysql database service mysqld_safe--skip-grant-tables-- skip-networking

In addition, terminal

Mysqlmysql > insertinto mysql.user (host, user, password,sll_cipher,x509_issuer,x509_subjec) values ('localhost',' root',password ('123456'),',')

You can complete the addition of database root users!

Tags: Data database user file configuration time password account number line content this method step terminal statement link association service login used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Huawei Shulou Information MySQL