Lost your root password? Let’s fix that!

Lost your root password? Let’s fix that!
root

Lost the root password for your MariaDB or MySQL server? Don’t panic—it’s very easy to recover it. I’ll guide you through a simple step-by-step process with just 5 steps, and your password will be recovered. Here’s how:

Download the mysqld server

   ps -ef | grep mysqld

   KILL -9

   KILL -9

2) Start the mysqld server with the options below:

   mysqld_safe –skip-grant-tables –skip-networking &

   –skip-grant-tables: The server will stop validating username and password (grant tables = tabelas de privilégios)
   –skip-networking: Since the server will accept any username and password, it makes sense for it to run only locally.

3) Access the MySQL/MariaDB console

   mysql

   You don’t need to mention username and password because the server will authenticate anything passed to it as username and password.

root

4) Change the root password.

   UPDATE mysql.user SET password = PASSWORD(‘123’) WHERE user = ‘root’;

   FLUSH PRIVILEGES;

When updating the user table directly, we will set the root password to 123. PASSWORD (in uppercase) is a MySQL function that converts the string '123' into an encrypted string. Running FLUSH PRIVILEGES is necessary for the new password to take effect immediately.

5) Stop and restart the server

Now you can stop the server normally since the password is known.

Attention! Some people might say this is a serious security flaw. That’s not true—unless the server installation wasn’t properly secured. To stop and start the mysqld server (with the option that disables authentication), you must have the privileges to do so. If a user gains access to the server’s operating system, and that user has privileges to kill the database server process and also restart it, believe me, the least of our worries is them restarting mysqld without authentication. It’s somewhat like giving a thief access to the main vault, then thinking they won’t break into the customers’ drawers once inside.

Schedule a meeting here

Visit our Blog

Learn more about databases

Learn about monitoring with advanced tools

root

Have questions about our services? Visit our FAQ

Want to see how we’ve helped other companies? Check out what our clients say in these testimonials!

Discover the History of HTI Tecnologia

Compartilhar: