How To Install MariaDB on CentOS 8

MariaDB is a popular, free and open-source database management system.

Installing MariaDB Server

yum install mariadb-server

Output:

[root@vps ~]# yum install mariadb-server
CentOS-8 - AppStream                            7.2 MB/s | 5.8 MB     00:00
CentOS-8 - Base                                 1.8 MB/s | 2.2 MB     00:01
CentOS-8 - Extras                                38 kB/s | 7.3 kB     00:00
Dependencies resolved.
================================================================================
 Package                    Arch   Version                      Repo       Size
================================================================================
Installing:
 mariadb-server             x86_64 3:10.3.17-1.module_el8.1.0+257+48736ea6
                                                                                                                                AppStream  16 M
Installing dependencies:
 mariadb                    x86_64 3:10.3.17-1.module_el8.1.0+257+48736ea6
                                                                                                                                AppStream 6.1 M
 mariadb-common             x86_64 3:10.3.17-1.module_el8.1.0+257+48736ea6
                                                                                                                                AppStream  62 k

Check the version of mariadb server by following command.

mysql -V

Output:

[root@vps ~]# mysql -V
mysql  Ver 15.1 Distrib 10.3.17-MariaDB, for Linux (x86_64) using readline 5.1
[root@vps ~]#

Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB and verify the status using the commands below.

systemctl enable mariadb

systemctl start mariadb

systemctl status mariadb

Output:

[root@vps ~]# systemctl enable mariadb
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.
[root@vps ~]# systemctl start mariadb
[root@vps ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pres>
     Active: active (running) since Fri 2020-08-21 10:44:31 EDT; 6s ago
         Docs: man:mysqld(8)

Next, To secure your MariaDB server.

You must secure the MariaDB server by running the following command for production use.

mysql_secure_installation

Output:

[root@vps ~]# 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.

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] y
 ... Success!

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
 ... Success!

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...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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!

Now, log in to the MariaDB server.

To login to the MariaDB server, enter the following command with the password set previously,

mysql -u root -p

Output:

[root@vps ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.17-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)]>

Creating new database, new database user and access the database.

Here We'll look to create new database, new database user and add the user to database. (eg: Here we'll cerate database called "crowncloud" and the new user called "ccuser1")

First, log in as root user:

mysql -u root -p

CREATE DATABASE crowncloud;

CREATE user ccuser1;

GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'secretePasswordHere';

Output:

[root@vps ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.17-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)]> CREATE DATABASE crowncloud;
Query OK, 1 row affected (0.002 sec)

MariaDB [(none)]> CREATE user ccuser1;
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'secretePasswordHere';
Query OK, 0 rows affected (0.004 sec)

Here we'll access to the database by the database user.

mysql -u ccuser1 -p'secretePasswordHere' crowncloud

show databases;

Output:

[root@vps ~]# mysql -u ccuser1 -p'secretePasswordHere' crowncloud
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.3.17-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 [crowncloud]> show databases;
+--------------------+
| Database           |
+--------------------+
| crowncloud         |
| information_schema |
+--------------------+
2 rows in set (0.004 sec)

MariaDB [crowncloud]>