This guide will help new users with the installation of MariaDB 10.5 on Amazon Linux 2. MariaDB is a free to use and open source relational database management system originally forked from MySQL. The latest stable release of MariaBD database server as of this article update is version 10.5 with cool new features that can be read from the release notes page.

Install MariaDB 10.5 on Amazon Linux 2

The version of MariaDB server available on the OS default repositories is not the latest as per the upstream project.

$ sudo  amazon-linux-extras | grep mariadb
 17  lamp-mariadb10.2-php7.2  available

To be able to install the latest MariaDB 10.5 on Amazon Linux 2 we’ll have to add MariaDB official RPM repository. The one that works for Amazon Linux 2 is CentOS 7 repository.

Step 1: Add MariaDB repository to Amazon Linux 2

Add MariaDB repository to Amazon Linux 2 machine by running the commands below as root or user with sudo privileges.

sudo tee /etc/yum.repos.d/mariadb.repo<<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

Before you begin installaton update OS package cache index:

$ sudo yum makecache 
Loaded plugins: dkms-build-requires, langpacks, priorities, update-motd
amzn2-core                                                                                                                               | 3.7 kB  00:00:00     
amzn2extra-docker                                                                                                                        | 1.3 kB  00:00:00     
mariadb                                                                                                                                  | 2.9 kB  00:00:00     
(1/3): mariadb/primary_db                                                                                                                |  60 kB  00:00:01     
(2/3): mariadb/other_db                                                                                                                  | 9.6 kB  00:00:00     
(3/3): mariadb/filelists_db                                                                                                              | 349 kB  00:00:02     
Metadata Cache Created

Confirm available repositories on your Amazon Linux instance.

$ sudo yum repolist 
Loaded plugins: dkms-build-requires, langpacks, priorities, update-motd
1 packages excluded due to repository priority protections
repo id                                                                    repo name                                                                      status
amzn2-core/2/x86_64                                                        Amazon Linux 2 core repository                                                 19,883
amzn2extra-docker/2/x86_64                                                 Amazon Extras repo for docker                                                      19
mariadb                                                                    MariaDB                                                                          84+4
repolist: 19,986

Step 2: Install MariaDB 10.5 on Amazon Linux 2

Once you have the repository added and working you can then begin the installation of MariaDB 10.5 on Amazon Linux 2 machine.

sudo yum install MariaDB-server MariaDB-client

Make sure there are no dependency issues and agree to installation.

Dependencies Resolved

================================================================================================================================================================
 Package                                      Arch                        Version                                         Repository                       Size
================================================================================================================================================================
Installing:
 MariaDB-client                               x86_64                      10.5.4-1.el7.centos                             mariadb                          13 M
 MariaDB-compat                               x86_64                      10.5.4-1.el7.centos                             mariadb                         2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.64-1.amzn2
 MariaDB-server                               x86_64                      10.5.4-1.el7.centos                             mariadb                          26 M
Installing for dependencies:
 MariaDB-common                               x86_64                      10.5.4-1.el7.centos                             mariadb                          81 k
 boost-program-options                        x86_64                      1.53.0-27.amzn2.0.3                             amzn2-core                      163 k
 galera-4                                     x86_64                      26.4.5-1.el7.centos                             mariadb                         9.5 M
 ncurses-compat-libs                          x86_64                      6.0-8.20170212.amzn2.1.3                        amzn2-core                      308 k
 perl-Compress-Raw-Bzip2                      x86_64                      2.061-3.amzn2.0.2                               amzn2-core                       32 k
 perl-Compress-Raw-Zlib                       x86_64                      1:2.061-4.amzn2.0.2                             amzn2-core                       58 k
 perl-DBI                                     x86_64                      1.627-4.amzn2.0.2                               amzn2-core                      804 k
 perl-Data-Dumper                             x86_64                      2.145-3.amzn2.0.2                               amzn2-core                       48 k
 perl-IO-Compress                             noarch                      2.061-2.amzn2                                   amzn2-core                      260 k
 perl-Net-Daemon                              noarch                      0.48-5.amzn2                                    amzn2-core                       51 k
 perl-PlRPC                                   noarch                      0.2020-14.amzn2                                 amzn2-core                       36 k
 socat                                        x86_64                      1.7.3.2-2.amzn2.0.1                             amzn2-core                      291 k

Transaction Summary
================================================================================================================================================================
Install  3 Packages (+12 Dependent packages)

Total download size: 53 M
Is this ok [y/d/N]: y

You are also asked to import GPG key:

Total                                                                                                                           764 kB/s |  53 MB  00:01:10     
Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <[email protected]>"
 Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
 From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y

Start and enable the database service.

sudo systemctl enable --now mariadb

MariaDB service should show as running.

$ systemctl status mariadb
● mariadb.service - MariaDB 10.5.4 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Thu 2020-07-02 20:31:32 UTC; 9s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 5009 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 4985 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 4983 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 4996 (mariadbd)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─4996 /usr/sbin/mariadbd

Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] Plugin 'FEEDBACK' is disabled.
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] Server socket created on IP: '::'.
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] InnoDB: Buffer pool(s) load completed at 200702 20:31:32
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] Reading of all Master_info entries succeeded
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] Added new Master_info '' to hash table
Jul 02 20:31:32 amazon-linux mariadbd[4996]: 2020-07-02 20:31:32 0 [Note] /usr/sbin/mariadbd: ready for connections.
Jul 02 20:31:32 amazon-linux mariadbd[4996]: Version: '10.5.4-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Jul 02 20:31:32 amazon-linux systemd[1]: Started MariaDB 10.5.4 database server.

Step 3: Secure and Test database connection

Run the database hardening script provided by the installer.

$ sudo 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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobodycan log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the 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!

Confirm you can login as root user with the password set.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.4-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)]> SELECT VERSION();
+----------------+
| VERSION()      |
+----------------+
| 10.5.4-MariaDB |
+----------------+
1 row in set (0.000 sec)

MariaDB [(none)]> QUIT
Bye

The marks the end of our guide on the installation of MariaDB 10.5 on Amazon Linux 2 server. Check other guides on Amazon Linux:

Install PHP on Amazon Linux

How To Install Podman in Amazon Linux 2

Linux Learning courses:

$15.22
$152.14
in stock
Udemy.com
$15.22
$152.14
in stock
Udemy.com
$15.22
$152.14
in stock
Udemy.com

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

twenty + 16 =