
Table of Contents
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 Maria Database 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 Maria Database, as the root account has full control over all databases and tables within the system. Therefore, it’s important to perform this Reset Maria Database root Password carefully and securely to prevent unauthorized access.
Stop the Maria Database Service
First, you need to stop the Maria Database service. You can do this by running:
sudo systemctl stop mariadb
If your system uses mysql instead of maria database for the service name, adjust the command accordingly.
Start Maria Database in Safe Mode with Skip-Grant-Tables
Next, start Maria database 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
Log in to the Mysql or Maria Database shell
root@localhost:~# mysql -u root
Set a new password.
Type the following command, replacing "new-password" with the new root password
MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
In old version of maria Database run the following command. Replace 'new password' with the new root password
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Stop the MySQL server using the following command.
You will be prompted to enter the new MySQL root password before the MySQL server shuts down
root@localhost:~# mysqladmin -u root -p shutdown
Start the MySQL/Maria Database server normally
root@localhost:~# service maria database start
Once started you can check the status of Maria database service using service maria database status command as shown below
root@localhost:~#service maria database status
Stop Maria database Safe Mode
Now, you need to stop the Maria Database 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 Maria database process by using the PID stored in mariadb.pid. The location of this file might vary, so adjust the path if necessary.
Start the Maria Database Service
Finally, start the Maria database service normally:
sudo systemctl start mariadb
Verify the New Password
Verify that you can now log in to the Maria Database 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 Maria Database shell.
Reset Maria Database 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 Maria Database environment, administrators can then execute commands to update the root password securely. This procedure is essential for maintaining control panel 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.