In this article, I will take you through the steps to Set MariaDB root password in Linux using mysql_secure_installation tool. If you are familiar with MySQL DB in Linux then you must be aware that MariaDB has now replaced MySQL DB in Latest RHEL/CentOS Based Systems. After installing MariaDB in your server you might wonder how to login to your database using root User. There are multiple ways to do that in which we are going to cover the simplest way to set mariadb root password is through mysql_secure_installation tool. This tool comes default with MariaDB so you don’t have to install it separately. Once you install MariaDB you can find this tool installed by default.
Set MariaDB root password in Linux
After successful installation of MariaDB in your server you can check and find
mysql_secure_installation tool under
/usr/bin path. You can either run this tool directly or by giving full path as shown below. Both of the approaches will work fine. Once you run this tool you will be asked to enter the current password and other few queries before you completely set the password.
However it is important to note here that this tool cannot be used to reset forgotten password. Since this tool requires your current password which is blank or empty after
MariaDB Installation so it will only work if you know the current password. If you want to reset forgotten mysql password then you can check the steps on How to reset MySQL root password on Redhat/CentOS 7.
rootuser to run
mysql_secure_installationtool. You can use any user with
sudoaccess to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide
sudoaccess to the User.
[root@localhost ~]# /usr/bin/mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here to set mariadb root password. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] n ... skipping. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n ... skipping. By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!