Linux

How to reset root password mariadb on linux

To reset the root account password in MariaDB, you can follow these steps. First, we need to stop the MariaDB service, then restart it in safe mode and make the necessary changes. Below are the detailed steps:

1. Stop MariaDB

systemctl stop mariadb

2. Start MariaDB in safe mode

mysqld_safe --skip-grant-tables &

3. Connect to MariaDB

mysql -u root

4. Reset the password

USE mysql;
UPDATE user SET password = PASSWORD('new_password') WHERE user = 'root';
FLUSH PRIVILEGES;
EXIT;

Replace new_password with the new password you want to set for the root account.

Note: Starting from MariaDB version 10.4 onwards, the structure of the user table in the mysql database has changed, and the password field has been replaced by authentication_string. Below is the corresponding command for the newer versions:

USE mysql;
UPDATE user SET authentication_string = PASSWORD('new_password') WHERE user = 'root';
FLUSH PRIVILEGES;
EXIT;

5. Restart MariaDB

systemctl stop mariadb
systemctl start mariadb

6. Connect to MariaDB

mysql -u root -p

Then, enter the new password.

Thanks for visit my website