DEV Community

Alaa Mekibes
Alaa Mekibes

Posted on

How to Reset a Forgotten MariaDB User Password

Did you or someone using MariaDB forget the password to an account? Don’t worry! Resetting a MariaDB user password on Linux is super easy. Here’s a quick guide with the commands and step-by-step instructions to help you out.

How to reset user password in MariaDB?

Change MariaDB password using command line

  • Open a terminal.
  • Stop the currently running MariaDB database.
sudo systemctl stop mariadb
Enter fullscreen mode Exit fullscreen mode
  • Restart the database process, but this time use the --skip-grant-tables option. This lets you connect to the database without needing a password.
sudo mysqld_safe --skip-grant-tables --skip-networking
Enter fullscreen mode Exit fullscreen mode
  • Now, open a new terminal.
  • Login to MariaDB as root. Don't worry, it won't ask you about the password.
mariadb -u root
Enter fullscreen mode Exit fullscreen mode
  • Run the FLUSH PRIVILEGES command and then change the root password with the command below. Change this NEW_PASSWORD_HERE to your new password. Past these commands line by line inside MariaDB Monitor.
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD_HERE';
exit
Enter fullscreen mode Exit fullscreen mode
  • Close your first terminal.
  • Stop the current mysqld process properly, and then restart your MariaDB server. Line by line.
sudo pkill mysqld 
sudo systemctl start mariadb
Enter fullscreen mode Exit fullscreen mode
  • Congratulations! You’ve successfully changed the password. Now, go ahead and test it out!
mariadb -u root -p
Enter fullscreen mode Exit fullscreen mode

Thanks for reading!

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site