Resetting the root password for MariaDB

Pre-requisites: system root access (sudo)


1. Stop the MariaDB/MySQL service

sudo systemctl stop mariadb

(or mysql depending on your installation)


2. Start in safe mode (skip grant tables)

This allows you to log in without a password.

sudo mysqld_safe --skip-grant-tables --skip-networking &
  • --skip-grant-tables disables password checking.
  • --skip-networking prevents remote connections while you reset the password.

3. Log into the database

mysql -u root

4. Change the root password

For MariaDB 10.4+ (uses mysql_native_password)

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

5. Exit and restart normally

exit
sudo systemctl stop mariadb
sudo systemctl start mariadb

6. Test login

mysql -u root -p

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *