Reset MariaDB root password in Linux is a necessary procedure when the current password is lost or forgotten, ensuring that administrators can regain control over the database system. This process involves stopping the MariaDB service, restarting it with special privileges that bypass standard authentication mechanisms, and then executing commands within the MariaDB environment to set a new root password. By doing this, it restores secure access to the database, allowing for the management and operation of databases without compromising the integrity and security of the data stored within.
This operation is critical for maintaining the overall security posture of applications and services relying on MariaDB, as the root account has full control over all databases and tables within the system. Therefore, it’s important to perform this Reset MariaDB root Password carefully and securely to prevent unauthorized access.

Follow these steps to reset your MariaDB root password on a Linux system:
Stop the MariaDB Service
First, you need to stop the MariaDB service. You can do this by running:
sudo systemctl stop mariadb
If your system uses mysql instead of mariadb for the service name, adjust the command accordingly.
Start MariaDB in Safe Mode with Skip-Grant-Tables
Next, start MariaDB in safe mode without granting table privileges. This mode allows anyone to connect to the database server without a password but with full privileges, which is why it’s crucial to ensure no unauthorized users have access to the server during this process.
sudo mysqld_safe --skip-grant-tables --skip-networking &
The --skip-networking option prevents remote connections, enhancing security during the Reset MariaDB root Password process.
Log into MariaDB without a Password
Now, connect to the MariaDB server as the root user:
mysql -u root
Reset MariaDB root Password
Once logged in, it’s time to Reset MariaDB root Password. You can do this by running the following command. Make sure to replace new_password with your new desired password.
MariaDB 10.1.20 and newer:
USE mysql;
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
MariaDB 10.1.19 and earlier:
USE mysql;
FLUSH PRIVILEGES;
UPDATE user SET password=PASSWORD("new_password") WHERE User='root';
FLUSH PRIVILEGES;
After executing the appropriate command for your version, you can exit the MySQL prompt with:
EXIT;

Stop MariaDB Safe Mode
Now, you need to stop the MariaDB server that is running in safe mode. You can find the process ID (PID) and kill the process, or if you started mysqld_safe as a job in the background (with & as in the command above), you can use:
sudo kill cat /var/run/mariadb/mariadb.pid
This command kills the MariaDB process by using the PID stored in mariadb.pid. The location of this file might vary, so adjust the path if necessary.
Start the MariaDB Service
Finally, start the MariaDB service normally:
sudo systemctl start mariadb
Verify the New Password
Verify that you can now log in to the MariaDB server with the new root password:
mysql -u root -p
You will be prompted to enter the new password to Reset MariaDB root Password. After entering it, you should gain access to the MariaDB shell.

Reset MariaDB root Password in Linux is a crucial task that may be required if the current password is forgotten or needs to be updated for security reasons. This process involves specific steps to ensure a smooth recovery without compromising the integrity of the database system. First, the MariaDB service must be stopped to initiate the Reset MariaDB root Password.
Then, the service is restarted with an option that allows for bypassing the standard authentication mechanisms, granting temporary elevated privileges. Within the MariaDB environment, administrators can then execute commands to update the root password securely. This procedure is essential for maintaining control over the database and ensuring that authorized personnel can continue managing and maintaining the system. Careful execution of the Reset MariaDB root Password is vital to prevent any potential security risks or unauthorized access to sensitive data stored in the MariaDB databases.