install MariaDB Server

Do you want to know how to install Mariadb 10.04 server on CentOS 8/RHEL 8 ? This post will help you to install MariaDB server. MariaDB is now defacto RDBMS in RHEL/CentOS after its seperation from the MySQL. We have already written other post on Mariadb Server, hence we will directly go to installation section.

In this post, we will do all the steps by creating the shell script and executing it. When we do our task by using scripts, it automates the task and quite faster then manual efforts.

Before we jump into installation section, we would like to strongly suggest to read the release notes of MariaDB 10.4 server.

Steps To Install MariaDB 10.4 Server on CentOS 8/RHEL 8

First we will create a simple bash script for installing the MariaDB Server.

Step 1: Create a file for creating bash script

vi install_mariadb_10.04_centos8.sh

Copy-Paste and save the given below content in the file.

#/bin/bash
#
# Install MariaDB Server version 10.4 on CentOS 8.
# Blog: https://sharadchhetri.com

# Declare a variable for new mariadb root password. If it is not given, then script won't run and will show help.
#

_root_new_passwd=${1?Require to give new root password, use -n }

# create new yum mariadb repo file and move to /etc/yum.repos.d dir
cat <mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
sudo mv mariadb.repo /etc/yum.repos.d/

#Install MariaDB Server
sudo dnf install -y MariaDB-server

# Enable as well as Start the mariadb service
sudo systemctl enable --now mariadb

## Resetting root password, removing database called 'test' and any related tables to it
sudo mariadb <<_EOF_
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("$_root_new_passwd");
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
_EOF_
###
echo "Installation finished"

Step 2: Change the permission of the script file.

chmod +x install_mariadb_10.04_centos8.sh

Step 3: Now run the script. You should give a new root password of MariaDB in first argument.

sh install_mariadb_10.04_centos8.sh MyNewRootPassword

Summary of install_mariadb_10.04_centos8.sh bash script

1. It create the mariadb yum repo file.
2. Then install the mariadb server by dnf command.
3. Then it enable and start the mariadb service.
4. At the end, it reset the root password. By default it is blank root password. As well as remove the 'test' database.

Login to MariaDB Server

Run the following command to login as root user in MariaDB server. Give the password which you have used in Step 3.

mariadb -u root -p

OR

mysql -u root -p

Output From Our System:

[sharad@mariadb01 ~]$ mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.4.13-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Manage MariaDB Service

1. Check status of MariaDB service.

sudo systemctl status mariadb

2. Start the MariaDB service.

sudo systemctl start mariadb

3. Stop the MariaDB service.

sudo systemctl stop mariadb

4. Re-start the MariaDB service.

sudo systemctl restart mariadb

5. Enable the MariaDB service. It start the service at system booting time.

sudo systemctl enable mariadb

6. Disable the MariaDB service. Means do not let service to start at booting time.

sudo systemctl disable mariadb

Read Some More Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.