Resetting and recovering a root password with MariaDB

The act of resetting a root password provides true currency for a system troubleshooter. It can happen—and yes, it does happen more times than you can imagine—but by following the next few steps, a crisis can be averted.

To begin, you will need to stop the MariaDB service like this:

# systemctl stop mariadb.service

The next step is to activate "safe mode" in the following way:

# mysqld_safe --skip-grant-tables --skip-networking

Now run the following sequence to access the MySQL console and connect to the database:

# mysql -u root
# use mysql;

At this point, we now want to create a new password for the root user, flush the new privileges, and exit the MySQL console like this:

# update user set ...

Get Troubleshooting CentOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.