How to reset MySQL root password for forgotten database

What if I have forgotten the password of the ROOT user of the mysql database? Methods as below:

1. Close the currently running mysqld service program:

systemctl stop mariadb

2. Use the mysqld_safe script to start the mysqld service in safe mode (without loading the authorization table)

 /usr/local/mysql/bin/mysqld_safe  --skip-grant-table  &

3. Use the root user with an empty password to log in to the database, and reset the password of the ROOT user

mysql  -u   root
Mysql> Update  mysql.user  set  password=password(‘新密码’)  where  user=’root’;
Mysql> flush   privileges;

Guess you like

Origin blog.csdn.net/APPLEaaq/article/details/109298263