Get the App
SLTechnology News&Howtos  ›  Database  › 

How to reset the Root password by MySQL/MariaDB

Shulou Source: shulou.com Published: 2022-05-31 19:49:44 09月30日 Update

This article mainly introduces how MySQL/MariaDB resets the Root password, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

Reset MySQL or MariaDB Root password

First, stop the database.

If you are using MySQL, type the following command and press Enter.

$ sudo systemctl stop mysql

For MariaDB:

$ sudo systemctl stop mariadb

Next, restart the database without permission checking using the following command:

$ sudo mysqld_safe --skip-grant-tables &

Here, the--skip-grant-tables option lets you connect without a password and all permissions. If you start the server with this option, it also enables the--skip-networking option, which prevents other clients from connecting to the database server. And, the & symbol is used to run commands in the background, so you can enter other commands in the following steps. Please note that the above command is dangerous and your database becomes insecure. You should only run this command for a short time to reset the password.

Next, log in to the MySQL/MariaDB server as root:

$ mysql

At the mysql > or MariaDB [(none)] > prompt, run the following command to reset the root password:

UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';

Replace NEW-PASSWORD in the above command with your own password.

Then, exit the mysql console by typing the following command.

FLUSH PRIVILEGES;exit

Finally, close the database that was previously running with the--skip-grant-tables option. To this end, run:

$ sudo mysqladmin -u root -p shutdown

You will be asked to enter the MySQL/MariaDB user password you set in the previous step.

Now, start MySQL/MariaDB service normally using the following command:

$ sudo systemctl start mysql

For MariaDB:

$ sudo systemctl start mariadb

Verify that the password has indeed changed using the following command:

$ mysql -u root -p Thank you for reading this article carefully. I hope that the article "MySQL/MariaDB How to Reset Root Password" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Commands passwords data databases runs articles services input server user next situation permissions danger security for this value interest at the same time background Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Shulou Technology NVidia Docker