How To Install MariaDB on CentOS 8

last updated in Categories ,

I am a new to MariaDB server and CentOS 8 sysadmin. How do I install MariaDB on CentOS 8 Linux server using the yum command?

Introduction – MariaDB is a free and open-source database management system and acts as a drop replacement for the Oracle MySQL DB server. It is a community-driven and developed branch of Oracle MySQL server. MariaDB is a multi-user, multi-threaded SQL database server. This page explains how to install the latest stable version of MariaDB on CentOS 8 server.

How to install MariaDB on CentOS 8

The procedure to install MariaDB on a CentOS Enterprise Linux 8 is as follows:

  1. Open the terminal application. Another option is to log in using the ssh command
    ssh user@centos-8-server-ip
  2. Installing the MariaDB on CentOS 8, type:
    sudo yum install mariadb-server
  3. Securing the MariaDB server in CentOS 8, run:
    sudo mysql_secure_installation
  4. Finally test your installation by running:
    mysql -u root -p

Let us see all steps and commands in details.

Installing MariaDB on CentOS 8 using the yum command

One can search for MariaDB package using the following syntax:
sudo yum search mariadb
Search for MariaDB packages on CentOS 8 Linux
Want to find out MariaDB server version? Try:
sudo yum info mariadb
Sample outputs:

Last metadata expiration check: 0:37:22 ago on Tuesday 01 October 2019 02:35:21 PM UTC.
Installed Packages
Name         : mariadb
Epoch        : 3
Version      : 10.3.11
Release      : 2.module_el8.0.0+35+6f2527ed
Arch         : x86_64
Size         : 38 M
Source       : mariadb-10.3.11-2.module_el8.0.0+35+6f2527ed.src.rpm
Repo         : @System
From repo    : AppStream
Summary      : A very fast and robust SQL database server
URL          : http://mariadb.org
License      : GPLv2 with exceptions and LGPLv2 and BSD.
Description  : MariaDB is a community developed branch of MySQL - a multi-user, multi-threaded

Installation

Next type the following yum command to MariaDB version 10.3.11 on CentOS 8:
$ sudo yum install mariadb-server
How to install MariaDB on CentOS 8

How to enable mariadb.service at CentOS 8 server boot time

Run the following systemctl command:
$ sudo systemctl enable mariadb.service

Created symlink /etc/systemd/system/mysql.service ? /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service ? /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service ? /usr/lib/systemd/system/mariadb.service.

How to start/stop/restart mariadb.service on CentOS 8

Again use the following syntax:
$ sudo systemctl stop mariadb.service
$ sudo systemctl start mariadb.service
$ sudo systemctl restart mariadb.service
$ sudo systemctl status mariadb.service

Start the MariaDB service with the systemct on CentOS 8

How to secure the MariaDB Server on CentOS 8

You must secure the MariaDB server by running the following command for production use:
$ sudo mysql_secure_installation

Securing the MariaDB Server
Securing the MariaDB Server on CentOS 8

How do I log in to the MariaDB server?

Use the mysql command as follows:
$ mysql -u root -p

Testing the MariaDB server installation on CentOS Linux 8
Testing the MariaDB server installation

Above commands indicates the installation has been successful on CentOS 8 server or VM. You can now add users and create databases for your applications written in PHP, Perl, Python and more.

How to add database on the MariaDB server

First, log in as root user:
$ mysql -u root -p mysql
Create a new MariaDB database called blog1. Type the following command at MariaDB> prompt:
CREATE DATABASE blog1;

How to add users on the MariaDB server

Create a new user called tristan for database called blog1 (feel free to replace username and secretePasswordHere with actual password):
GRANT ALL ON blog1.* TO tristan@localhost IDENTIFIED BY 'secretePasswordHere';
List all database:
show databases;
Quit from MariaDB:
quit
How to create the MariaDB users and database on Linux

How to connect to the MariaDB database nixcraft using vivek account

$ mysql -u tristan -p'secretePasswordHere' blog1
OR
$ mysql -u tristan -p blog1
How to connect to the MariaDB CentOS server using user account
For further information see:

Conclusion

You completed and secured MariaDB on CentOS 8 server. Further, you learned how to create users and databases on the MariaDB server. For more info see MariaDB site here and recommended MariaDB books here.

This entry is 1 of 5 in the Tutorial series. Keep reading the rest of the series:
  1. CentOS 8 install MariaDB
  2. OpenBSD install MariaDB database server
  3. RHEL 8 install MariaDB
  4. FreeBSD 11 install MariaDB
  5. Setup MariaDB SSL and secure connections from clients

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

1 comment

    Still, have a question? Get help on our forum!