Hướng dẫn Reset MySQL Or MariaDB Root Password

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

For MariaDB:

$ 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:

$ mysql

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: 
[2]- Done sudo mysqld_safe --skip-grant-tables

Now, start mysql/mariadb service normally using command:

$ sudo systemctl start mysql

For MariaDB:

$ 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!

Bài viết liên quan

Leave a Reply

Your email address will not be published. Required fields are marked *