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

Ubuntu 18.04 MySQL 8.0 installation and configuration method graphic tutorial

This article shares the installation and configur...

React's component collaborative use implementation

Table of contents Nesting Parent-child component ...

About the implementation of JavaScript carousel

Today is another very practical case. Just hearin...

Explaining immutable values ​​in React

Table of contents What are immutable values? Why ...

Detailed explanation of making shooting games with CocosCreator

Table of contents Scene Setting Game Resources Tu...

Two methods to implement Mysql remote connection configuration

Two methods to implement Mysql remote connection ...

Tutorial on building nextcloud personal network disk with Docker

Table of contents 1. Introduction 2. Deployment E...

In-depth discussion on auto-increment primary keys in MySQL

Table of contents Features Preservation strategy ...

Sample code for installing Jenkins using Docker

Two problems that are easy to encounter when inst...

Example code for implementing hexagonal borders with CSS3

The outermost boxF rotates 120 degrees, the secon...

Detailed explanation of the difference between alt and title

These two attributes are often used, but their di...

Implementing Binary Search Tree in JavaScript

The search binary tree implementation in JavaScri...