Updated April 12, 2023
Introduction to MariaDB reset root password
MariaDB Reset Root Password is the MariaDB command which helps to recover the entrance to the server whenever the user loses or forgets the root password of the MariaDB server. With this MariaDB Reset Root Password, one can still gain excess to the MariaDB server by resetting the password of the root account if the user account is a sudo-enabled. The MariaDB Reset Root Password is performed by using different commands to recover the root password which depends on the version of MySQL server that is running on the user’s system. The need to have the root user privileges to reset the root password in MariaDB server when a user needs to change it or does not remember the set password.
Syntax
Let us discuss the steps to be followed for resetting the password to new one in MariaDB server as follows:
There are some prerequisites for recovering the MariaDB root password that needs to be operated listed as follows:
Having access to the Linux server functioning MariaDB or MySQL holding a sudo user.
- Recognizing the Database version: On the basis of the database implemented and its version, the user requires to apply several commands to reset the root password. Here, we can test the version of the MariaDB server using the succeeding command as: mysql –version
The output for this using MariaDB will be:
mysql Ver 15.1 Distrib 5.5.52-MariaDB, Linux (x86_64) using readline 5.1
- Discontinuing the Database server: Here, for modifying the root password in the server we need to shut down the MariaDB database server before and for this we need to use command as follows in MariaDB: Sudo systemctl stop mariadb. After this when the server has been stopped, we can access it for resetting the root password manually.
- Without Permission check restart the database server: When the user executes MariaDB but not loading information regarding the root privileges then, it will permit to manage the database command line having root privileges and not delivering the password. This will make you to access the server but not knowing it. We will start the database table but not loading the grant tables which stores information of user privileges or enabling networking as: sudo mysqld_safe –skip-grant-tables –skip-networking &, using ampersand in the command at the end will proceed the process to run in the background hence continuing using the terminal.
- Altering the root password: For modern MySQL versions we can change the root user password in a simple way applying the command ALTER USER. But without loading the grant tables, this will not work. Therefore, we will reload it by allotting the command FLUSH PRIVILEGES.
After that set any new password to the root user using the following command but for MySQL 5.7.6 version and MariaDB 10.1.20 and later ones:
ALTER USER 'root@localhost' IDENTIFIED BY 'novel_password';
FLUSH PRIVILEGES;
Also, for version MySQL 5.7.5 or MariaDB 10.1.20 and earlier ones:
SET PASSWORD FOR 'root@localhost' = PASSWORD(‘novel_password’);
FLUSH PRIVILEGES;
OK will be resulted if everything goes well in both the above cases for password reset of user root.
- Restart the database routinely: Firstly, we need to stop the illustration of the database server which was initiated manually in third step as: sudo systemctl start mariadb.
- In MariaDB, with this the user has administrative access to the MariaDB server renovated. This time we need to be ensure if the new root password chosen is robust & secure and should be kept safely.
How to reset the root password in MariaDB?
- There is slight difference between changing the password and resetting the password in general definition. Suppose, when you have the root password, one can easily establish connection to the database logging as the root user where one can change the password simply. Not only the root password, one can change any other user account password too.
- But what to do when a user forgets the password of the root user? This means that the root user will not be able to connect to the MariaDB server unless password is correct or valid one. Here, the root user holds the utmost privileges so therefore, no one can alter its password using any other accounts. Thus, in this condition we require to perform few supplementary steps for resetting the MariaDB root password.
- The MariaDB is assembled on upper level of MySQL. It is very prevalent for web hosting necessities. So, the steps to reset the password in MariaDB will be similar like MySQL also. Hence, any SQL query command which functions for MySQL will also work as well for MariaDB. But only the alteration that need to be done in the commands is to start and stop of MySQL server.
- If the user is working on Windows OS, then we need to use mysqladmin or mysqld through the command prompt for starting or stopping the MySQL server, which are positioned in the MariaDB installation bin folder in the system.
Examples
Let us provide an example explaining the query how it resets the MariaDB user account password with super privileges on forgetting it with the command as follows:
Firstly, we have a list of user accounts present in my phpmyadmin MariaDB server shown as below:
As you can view there are few users apart from the global super user root such as slaveuser and technouser. Let us then take a demonstration for resetting the technouser password as the password is forgotten is supposed.
So, the MariaDB reset root password will follow the similar steps as mentioned above in the syntax section and then the reset main query will be as:
ALTER USER 'tchnouser@localhost' IDENTIFIED BY 'techno@123';
FLUSH PRIVILEGES;
Conclusion
- In MariaDB or MySQL, the root user is also like any other user available in the server account. Perhaps, since it is known to be the super user, so altering or resetting its password might be bit tricky and one cannot modify the root password from other user login accounts.
- Hence, this MariaDB Reset Root Password helps to recover the forgotten password in the server and apply new one with super user privilege.
Recommended Articles
We hope that this EDUCBA information on “MariaDB reset root password” was beneficial to you. You can view EDUCBA’s recommended articles for more information.