Database plays a very important part in every business, industries, banking sector, etc. and without it you can’t think of having a collective data at one place. There are many popular databases present now like Oracle, mysql etc and MariaDB is also one of those which is gradually becoming very popular because it is free and easy to use. In this tutorial, I will tell you how to install Mariadb and secure it by setting the root password.
MariaDB is also from the creators of MySQL and is an open source software and free to use. Installing MariaDB is very easy, just look for packages in your Yum repo and install it.
If you are preparing for Red hat certified engineer (RHCE) certification on RHEL7, then you must know how to install MariaDB, securing it with the root password, taking backup, restoring a database etc. as this in syllabus of RHCE 7.
How to Install MariaDB and Secure it in RHEL7 and CentOS7
1. Login to your Linux operating system and install MariaDB with below command. For this your repository should be already configured else you won’t be able to install anything.
yum groupinstall "mariadb" -y
Above command will install the mariadb server on your machine and its related dependencies.
2. Once MariaDB rpm is installed on your RHEL 7 system, you can do your firewall settings. This setting is very important and will help MariaDB to work properly. So add mariadb service to firewall and save the setting as below.
# firewall-cmd --permanent --add-service=mysql
# firewall-cmd --permanent --add-port=3306/tcp
# firewall-cmd --reload
3. Once the database (Mariadb) is installed, you should enable it, so that it can even start after the server is rebooted. Also do not forget to start Mariadb and check it’s status. For this follow below commands and check status of Mariadb service.
# systemctl enable mariadb
# systemctl start mariadb
# systemctl status mariadb
4. Now to secure Mariadb, you will have to set root password for mariadb, remove anonymous user, drop test database etc. “mysql_secure_installation” command will be used for this.
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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.
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
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
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
Remove anonymous users? [Y/n] y
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] y
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] y
- Dropping test database...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
So, this is how you install MariaDB in Red hat Enterprise Linux 7 or CentOS 7 and secure it.
After installation, you can login to Mariadb and check available databases. I have made complete video on it. Do check below video.
Hope you have found this tutorial helpful and got one more RHCE objective completed. I will soon make another video and tutorial on how to backup and restore a database in MariaDB and create a simple database schema and perform simple SQL queries against a database. Till then you can subscribe to my Newsletter.