Reset MySQL or MariaDB Root password.
First, stop the database server.
If you use MySQL, type the following command and hit ENTER key.
$ sudo systemctl stop mysql
$ sudo systemctl stop mariadb
Next, restart the database server without permission-checking using the following command:
$ sudo mysqld_safe --skip-grant-tables &
Next, login to your MySQL/MariaDB server as root user:
At the mysql> or MariaDB [(none)]> prompt, run the following command to reset the root user password:
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Replace password in the above command with your own password.
Then, type following commands to exit from the mysql console.
Finally, shutdown the running database server that you started earlier with
--skip-grant-tablesoption. To do so, run:
$ sudo mysqladmin -u root -p shutdown
You will be asked to enter your mysql/mariadb root user password that you set in the previous step.
Enter password: - Done sudo mysqld_safe --skip-grant-tables
Now, start mysql/mariadb service normally using command:
$ sudo systemctl start mysql
$ sudo systemctl start mariadb
Verify if the password has really been changed using the following command:
$ sudo mysql -u root -p
Chúc các bạn thành công!