How To Install MariaDB Server on AWS Linux 2
Enjoying this content? Subscribe to the Channel!
Lightning Fast Setup: Installing and Running MariaDB on Amazon Linux 2 (The Easy Way!)
Hello and welcome back to Darren’s Tech Tutorials!
If you’re working in the AWS ecosystem, chances are you need a robust, reliable, and open-source database solution running on your Amazon Linux 2 instances. MariaDB, a high-performance fork of MySQL, is often the perfect choice.
In this guide, we’ll walk through the entire installation process from start to finish. We’ll cover installation, service management, and finally, how to successfully log into your new database server. Let’s get that server humming!
Prerequisites
Before we dive in, make sure you are logged into your Amazon Linux 2 instance (usually via SSH) and have sudo privileges.
Step 1: Installing MariaDB Server using yum
Amazon Linux 2 uses the yum package manager, making the installation of popular services like MariaDB incredibly simple.
First, it’s always best practice to ensure your package lists are up to date:
sudo yum update -y
Once the system is updated, we can install the MariaDB server package. We use the -y flag to automatically agree to the installation prompts:
sudo yum install mariadb-server -y
This command downloads all necessary files and dependencies. Once the command completes, MariaDB is installed on your system, but it is not yet running!
Step 2: Starting the MariaDB Service
The installation process generally puts the necessary configuration files in place, but you must manually start the database service for the first time. We use the systemctl command for service management:
sudo systemctl start mariadb
If the command executes without error, congratulations—your MariaDB server is now running!
To quickly confirm its status, you can run:
sudo systemctl status mariadb
You should see an output indicating that the service is active (running).
Step 3: Ensuring MariaDB Starts on Boot
While the database is running now, if your Amazon Linux 2 instance were to reboot (for maintenance or updates), the MariaDB service would not automatically restart, leading to potential downtime.
To make the MariaDB service persistent across reboots, we need to enable it:
sudo systemctl enable mariadb
You will likely see a response indicating that a symbolic link has been created. This step ensures that whenever your server boots up, MariaDB starts automatically, guaranteeing high availability.
Step 4: Securing and Logging Into the Server
Now that the server is installed, running, and persistent, the final critical step is security. MariaDB ships with an excellent script to handle basic security configurations, which we highly recommend running immediately:
sudo mysql_secure_installation
This script will prompt you through several vital configurations:
- Setting the root password: Since you are likely running this on a fresh installation, there is no existing root password. Follow the prompts to set a strong password.
- Removing anonymous users: These users are only for testing and should be removed in production environments.
- Disallowing remote root login: A critical security measure.
- Removing the test database: Deletes the default, insecure database.
Answer Yes (Y) to these prompts. Once completed, your MariaDB installation is significantly more secure.
Logging In to Verify
Finally, let’s log in and ensure everything is working correctly. Since we are running on Linux, we can log in as the root database user using sudo (after providing the password you just set):
sudo mysql -u root -p
If successful, you will be greeted by the MariaDB prompt:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is XX
Server version: 10.5.15-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)]>
You can now start creating databases, users, and tables! To exit the prompt, simply type exit;
Conclusion
That’s all there is to it! In just a few quick commands, you have successfully installed, started, enabled, and secured a robust MariaDB database server running on Amazon Linux 2. This setup is the perfect foundation for any web application or service you plan to host in the AWS cloud.
Did this guide help you get up and running? We certainly hope so! If you found this tutorial useful, please smash that like button on the corresponding video and subscribe to Darren’s Tech Tutorials for more clear, practical guides just like this one! Happy coding!