How to Install MariaDB on Amazon Linux 2023
How to Install MariaDB on Amazon Linux 2023
Dear Reader, I hope you are doing well today. Before I start, let me tell you that In my last few posts, I have shared with you how to install Git, Ansible, Nginx, Apache, Jenkins, MySQL, Docker, Java, Python, PHP 8.1 etc. on Amazon Linux 2023 or AL2023 EC2 Instance.
In this article, you’ll learn how to install MariaDB on Amazon Linux 2023 EC2 instance in a step-by-step manner. Additionally, I will share the bash or CLI script to install MariaDB on Amazon Linux 2023 by the end of this tutorial.
Shall we start?
Alright, let’s go !!!
Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.
A bit on MariaDB and Amazon Linux 2023
MariaDB: MariaDB is a fork of MySQL, developed by some of the original MySQL developers and promised to stay open source always.
- You can use it as a drop-in replacement for MySQL.
- Moreover, Some popular organisations such as Facebook, Wikipedia, WordPress etc. use MariaDB.
- It is available for a variety of platforms, including Linux, Windows, and macOS
- Can be used in web applications, e-commerce applications or high traffic applications etc.
Amazon Linux 2023: Amazon Linux 2023 or AL2023 is the next-generation Amazon Linux AMI provided by AWS. It is rpm-based and optimized for the cloud. It is designed with the latest Linux innovations to deliver high-performance and stable Linux systems.
Prerequisite
A running Amazon Linux 2023 EC2 Instance
You can follow my tutorial to launch an Amazon Linux 2 Instance within minutes.
Steps to Install MariaDB on Amazon Linux 2023 Instance
- Connect to your Amazon Linux 2023 EC2 Instance
- Update Amazon Linux 2023 Package Repository to Latest
- Search for MariaDB
- Install MariaDB on the Amazon Linux 2023 Instance
- Verify MariaDB Installation
- Start and Enable MariaDB Service
- Secure MariaDB Installation
- Connect to MariaDB
Step 1: Connect to your Amazon Linux 2023 EC2 Instance
Above all, If you already have an Amazon Linux 2023 instance up and running, you are all set to install MariaDB on it. Otherwise, you can use my previous post to create an Amazon Linux 2023 Instance.
Once running, select your instance and click on Connect as shown in the below screenshot.
After that, verify that ec2-user is showing in the user name field and click Connect again.
In a matter of seconds, you should be connected to your instance.
Important Note: If you prefer connecting from your local, feel free to use the command- ssh -i /path/my-key-pair.pem ec2-user@instance-public-ip
Step 2: Update Amazon Linux 2023 Package Repository to the Latest
Before you install MariaDB software, let’s update our system to the latest.
sudo dnf update
If there is any update available, it will be installed. Albeit, Sometimes you will see new upgrades are available shown below-
Run the suggested command to upgrade your Amazon Linux 2023. Once your system is up to date, you can proceed to the next step.
Step 3: Search for MariaDB Package on Amazon Linux 2023
If you search for MariaDB using the below command-
dnf search mariadb
It displays all the packages that match Mariadb. As you can see below we can see the MariaDB server as well.
Let’s install the shown MariaDB package.
Step 4: Install MariaDB on Amazon Linux 2023
The one-liner to install MariaDB on Amazon Linux 2023 comes down to
sudo dnf install mariadb105-server
Type the above command and hit enter.
Type y when the prompt asks for it And MariaDB gets installed in a jiffy.
[ec2-user@ip-172-31-2-26 ~]$ sudo dnf install mariadb105-server
Last metadata expiration check: 0:11:33 ago on Wed Sep 6 15:10:41 2023.
Dependencies resolved.
======================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================
Installing:
mariadb105-server x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 10 M
Installing dependencies:
mariadb-connector-c x86_64 3.1.13-1.amzn2023.0.3 amazonlinux 196 k
mariadb-connector-c-config noarch 3.1.13-1.amzn2023.0.3 amazonlinux 9.2 k
mariadb105 x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 1.6 M
mariadb105-common x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 31 k
mariadb105-errmsg x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 215 k
mysql-selinux noarch 1.0.4-2.amzn2023.0.3 amazonlinux 36 k
perl-B x86_64 1.80-477.amzn2023.0.5 amazonlinux 180 k
perl-DBD-MariaDB x86_64 1.22-1.amzn2023.0.4 amazonlinux 153 k
perl-DBI x86_64 1.643-7.amzn2023.0.3 amazonlinux 700 k
perl-Data-Dumper x86_64 2.174-460.amzn2023.0.2 amazonlinux 55 k
perl-File-Copy noarch 2.34-477.amzn2023.0.5 amazonlinux 21 k
perl-FileHandle noarch 2.03-477.amzn2023.0.5 amazonlinux 16 k
perl-Math-BigInt noarch 1:1.9998.18-458.amzn2023.0.2 amazonlinux 189 k
perl-Math-Complex noarch 1.59-477.amzn2023.0.5 amazonlinux 47 k
perl-Sys-Hostname x86_64 1.23-477.amzn2023.0.5 amazonlinux 18 k
perl-base noarch 2.27-477.amzn2023.0.5 amazonlinux 17 k
Installing weak dependencies:
mariadb105-backup x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 6.2 M
mariadb105-cracklib-password-check x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 16 k
mariadb105-gssapi-server x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 18 k
mariadb105-server-utils x86_64 3:10.5.18-1.amzn2023.0.1 amazonlinux 216 k
Transaction Summary
======================================================================================================================================================
Install 21 Packages
Total download size: 20 M
Installed size: 117 M
Is this ok [y/N]: y
It is showing what’s getting installed along with MariaDB.
Once installed, you will see
Step 5: Verify MariaDB Installation
mariadb -V
As you can see MariaDB 10.5 is successfully installed on Amazon Linux 2023. We verified the version using mariadb -V.
[ec2-user@ip-172-31-2-26 ~]$ mariadb -V
mariadb Ver 15.1 Distrib 10.5.18-MariaDB, for Linux (x86_64) using EditLine wrapper
[ec2-user@ip-172-31-2-26 ~]$
Step 6: Start and Enable the MariaDB Service
As of now, we have installed MariaDB 10.5 in our Amazon Linux 2023 instance. However, it’s not yet running.
You can run the below set of commands to start and enable it to auto-start on boot.
sudo systemctl start mariadb //Starts MariaDB service
sudo systemctl enable mariadb //Enabled MariaDB service to restart on bot
systemctl status mariadb //Check MariaDB service running status
Run the above commands one by one to start the MariaDB service, enable it to start on reboots and check its running status. Here is how it looks.
[ec2-user@ip-172-31-2-26 ~]$ sudo systemctl start mariadb
[ec2-user@ip-172-31-2-26 ~]$ sudo 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.
[ec2-user@ip-172-31-2-26 ~]$ systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Active: active (running) since Wed 2023-09-06 15:27:20 UTC; 22s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 27010 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 12 (limit: 1114)
Memory: 66.0M
CPU: 520ms
CGroup: /system.slice/mariadb.service
└─27010 /usr/libexec/mariadbd --basedir=/usr
Congratulation !!!
You have successfully installed and started MariaDB on your Amazon Linux 2023 EC2 Instance.
Step 7: Secure MariaDB Installation
After the installation of MariaDB, it’s very important to secure the installation and set up a strong password for root. Additionally, set some additional settings to make the database more secure.
sudo mysql_secure_installation -p
First of all, it will ask for your password, since we are yet to set any. Just hit enter for none. For the rest of the settings, it will prompt you for your password before making any changes. Enter the password to apply the changes.
[ec2-user@ip-172-31-2-26 ~]$ sudo mysql_secure_installation -p
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):
Enter password:
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can 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
Enter password:
Enabled successfully!
Reloading privilege tables..
Enter password:
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
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
Enter password:
... 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
Enter password:
... 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...
Enter password:
... Success!
- Removing privileges on test database...
Enter password:
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
Enter password:
... 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!
[ec2-user@ip-172-31-2-26 ~]$
Step 8: Connect to MariaDB
mysql -u root -p
[ec2-user@ip-172-31-2-26 ~]$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 33
Server version: 10.5.18-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)]>
We are successfully able to connect to MariaDB as you can see in the prompt above. You can run MySQL commands.
For instance-
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.000 sec)
MariaDB [(none)]>
Final Script to Install MariaDB on Amazon Linux 2023-
#!/bin/bash
echo "Installing MariaDB on Amazon Linux 2023"
sudo dnf update
sudo yum install mariadb105 -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
Conclusion
In this how-to guide, we talked about How to Install MariaDB on Amazon Linux 2023 Instance.
We saw that MariaDB is available in the default repository of Amazon Linux 2023. Also, AWS recommends MariaDB. Therefore, it was very straightforward to install.
Later, we did post-installation configuration and ran a sample MySQL command.
Were you able to install MariaDB on Amazon Linux 2023 using this tutorial? Let me know in the comment section.
Enjoyed the content?
Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.
Don’t forget to motivate us-
- Follow us on
- Share this post with your friends