How to reset Root password in MariaDB
This article is about how to reset the Root password in MariaDB, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
First, stop the database.
If you are using MySQL, please enter 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 allows you to 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. Also, 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 will become 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 user password:
UPDATE mysql.user SET Password=PASSWORD ('NEW-PASSWORD') WHERE User='root'
Replace NEW-PASSWORD in the above command with your own password.
Then, enter the following command to exit the mysql console.
FLUSH PRIVILEGES;exit
* to close the database that was previously run with the-- skip-grant-tables option. To do this, 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 the MySQL/MariaDB service normally using the following command:
$sudo systemctl start mysql
For MariaDB:
$sudo systemctl start mariadb
Use the following command to verify that the password has indeed changed:
The above $mysql-u root-p is how to reset the Root password in MariaDB. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.