How To Install MariaDB 10.7 on Amazon Linux 2

Posted on 91 views

This guide will help new users with the installation of MariaDB 10.7 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.7 with cool new features that can be read from the release notes page.

Install MariaDB 10.7 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    \
54  mariadb10.5              available    [ =stable ]

To be able to install the latest MariaDB 10.7 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.

Let’s first update and reboot the system

sudo yum -y update
sudo reboot

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.

curl -LsS -O
sudo bash mariadb_repo_setup --os-type=rhel  --os-version=7 --mariadb-server-version=10.7

Repository addition output:

# [info] Skipping OS detection and using OS type 'rhel' and version '7' as given on the command line
# [info] Checking for script prerequisites.
# [info] MariaDB Server version 10.7 is valid
# [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
# [info] Adding trusted package signing keys...
/etc/pki/rpm-gpg ~
# [info] Successfully added trusted package signing keys
# [info] Cleaning package cache...
Failed to set locale, defaulting to C
Loaded plugins: langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker mariadb-main mariadb-maxscale mariadb-tools
Cleaning up everything

Before you begin installaton update OS package cache index:

sudo rm -rf /var/cache/yum
sudo yum makecache

Confirm available repositories on your Amazon Linux instance.

$ sudo yum repolist 
repo id                                                                                       repo name                                                                                         status
amzn2-core/2/x86_64                                                                           Amazon Linux 2 core repository                                                                    27317
amzn2extra-docker/2/x86_64                                                                    Amazon Extras repo for docker                                                                        56
mariadb-main                                                                                  MariaDB Server                                                                                     80+3
mariadb-maxscale                                                                              MariaDB MaxScale                                                                                      4
mariadb-tools                                                                                 MariaDB Tools                                                                                      14+1
repolist: 27471

Step 2: Install MariaDB 10.7 on Amazon Linux 2

Once you have the repository added and working you can then begin the installation of MariaDB 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
 MariaDB-client                                        x86_64                               10.7.3-1.el7.centos                                      mariadb-main                                15 M
 MariaDB-compat                                        x86_64                               10.7.3-1.el7.centos                                      mariadb-main                               2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.amzn2
 MariaDB-server                                        x86_64                               10.7.3-1.el7.centos                                      mariadb-main                                25 M
Installing for dependencies:
 MariaDB-common                                        x86_64                               10.7.3-1.el7.centos                                      mariadb-main                                81 k
 boost-program-options                                 x86_64                               1.53.0-27.amzn2.0.5                                      amzn2-core                                 161 k
 galera-4                                              x86_64                               26.4.11-1.el7.centos                                     mariadb-main                               9.9 M
 libpmem                                               x86_64                               1.3-3.amzn2                                              amzn2-core                                  36 k
 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                                                           amzn2-core                                 291 k

Transaction Summary
Install  3 Packages (+13 Dependent packages)

Total download size: 54 M
Is this ok [y/d/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.7.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
   Active: active (running) since Thu 2022-03-03 00:03:20 UTC; 3s ago
     Docs: man:mariadbd(8)
  Process: 3222 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 3197 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: 3194 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 3208 (mariadbd)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─3208 /usr/sbin/mariadbd

Step 3: Secure and Test database connection

Run the database hardening script provided by the installer.

$ sudo mariadb-secure-installation


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] n
 ... skipping.

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 14
Server version: 10.7.3-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.7.3-MariaDB |
1 row in set (0.000 sec)
MariaDB [(none)]> QUIT

The marks the end of our guide on the installation of MariaDB 10.7 on Amazon Linux 2 server.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.