MySQL/MariaDB Root Password Reset Tutorial

MySQL/MariaDB Root Password Reset Tutorial

Preface

Forgotten passwords are a problem we often encounter. If you have forgotten or lost the root password to your MySQL or MariaDB database, you can still access and reset the password if you have access to the server and a sudo-enabled user account.

A few months ago, I installed LAMP on Ubuntu 18.04. Today I tried to log into the database as root, but I totally forgot my password. After a bit of Googling and reading some articles, I was able to successfully reset my password. For those who are wondering how to do that, this short tutorial explains how to reset MySQL or MariaDB Root password in Unix-like operating systems. Let’s take a look at the detailed introduction.

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 checks using the following command:

$ sudo mysqld_safe --skip-grant-tables &

Here, the --skip-grant-tables option lets you connect without a password and with all privileges. If you start the server with this option, it also enables the --skip-networking option, which is used to prevent other clients from connecting to the database server. Also, the & symbol is used to run the command in the background, so you can enter additional 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 period of time to reset your password.

Next, log in to the MySQL/MariaDB server as the 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('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

Finally, shut down the database that you previously ran 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 that 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

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

$ mysql -u root -p

That’s all for today. There's more good stuff. Stay tuned!

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • The best solution for resetting the root password of MySQL 8.0.23
  • How to reset the root password in Linux mysql-5.6
  • The easiest way to reset mysql root password
  • Solve the problem of resetting the Mysql root user account password
  • Complete steps to reset the root user password in mysql8
  • How to reset the root password in mysql8.0.12
  • Tutorial on resetting the root password of Mac MySQL
  • How to reset MySQL root password under Windows
  • Two ways to reset the root password of MySQL database using lnmp
  • How to Reset MySQL or MariaDB Root Password in Linux
  • Tutorial on resetting the root password of MySQL under CentOS
  • How to reset MySQL root password

<<:  SSH port forwarding to achieve intranet penetration

>>:  How to solve the problem of Chinese garbled characters when inserting table data into MySQL

Recommend

Docker uses dockerfile to start node.js application

Writing a Dockerfile Taking the directory automat...

VMware vSAN Getting Started Summary

1. Background 1. Briefly introduce the shared sto...

Detailed process of installing logstash in Docker

Edit docker-compose.yml and add the following con...

Xftp download and installation tutorial (graphic tutorial)

If you want to transfer files between Windows and...

Simple CSS text animation effect

Achieve results Implementation Code html <div ...

Explanation of the execution priority of mySQL keywords

As shown below: from table where condition group ...

HTML+CSS+JS to implement the Don't Step on the Whiteboard game

Table of contents Background 1. Thought Analysis ...

How to use VIM editor in Linux

As a powerful editor with rich options, Vim is lo...

Detailed explanation of mysql deadlock checking and deadlock removal examples

1. Query process show processlist 2. Query the co...

JavaScript to achieve dynamic color change of table

This article shares the specific code for JavaScr...

Implementation of CSS child element selection parent element

Usually a CSS selector selects from top to bottom...

Detailed explanation of how to use JavaScript paging component

The pagination component is a common component in...

MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

This article shares with you the installation and...