In the world of database engines, MySQL and MariaDB are two of the major players. MariaDB is practically MySQL with some key changes. It’s a community-developed fork of MySQL backed by commercial support, for example, Wikipedia, Google, WordPress.com, etc. MariaDB is free and open-source and guaranteed to stay so.
In this guide, we will guide you through the steps of installing MariaDB on CentOS 7.
MariaDB on CentOS 7
MariaDB is an RDBMS (relational database management system). It comes with all major open-source storage engines. The MariaDB source code is publicly available on GitHub.
Oftentimes, MariaDB is installed as a part of the LEMP (Linux, NGINX, MySQL/MariaDB, and PHP/Python/Perl) or LAMP (Linux, Apache, MySQL/MariaDB, and PHP/Python/Perl) stacks.
Prerequisites
The first requirement is having a properly configured CentOS server. This guide assumes that you already have one configured.
Performing any system-level changes requires root privilege. CentOS has strict control over root access. Installing and configuring MariaDB requires you to have root access. Alternatively, a user with sudo privilege will also work.
If MariaDB is going to be a part of the LAMP stack, then check out this guide on how to install and configure the LAMP stack on CentOS 7. This guide will elaborate on the MariaDB installation section.
Installing MariaDB
Depending on the version of MariaDB, there are two ways of installing MariaDB on CentOS 7.
-
Installing MariaDB 5.5
This is the easiest way of installing MariaDB on CentOS. The CentOS package servers host MariaDB 5.5 packages. Thus, we can use YUM to grab and install it right away.
First, check out the MariaDB package info:
1 |
yum info mariadb-server |
Then, install MariaDB 5.5:
1 |
sudo yum install mariadb-server |
-
Installing MariaDB 10.4
Both MariaDB 5.5 and MariaDB 10.4 are mainstream releases. As the release version suggests, MariaDB 10.4 comes with substantial improvements over MariaDB 5.5.
Installing MariaDB 10.4 is a bit tricky. It isn’t directly available from the CentOS package repositories. Thankfully, MariaDB has a dedicated YUM repository to help the package management process.
First, add the MariaDB YUM repository:
1 |
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup |
1 |
chmod +x mariadb_repo_setup |
1 |
sudo ./mariadb_repo_setup |
Once the repo is installed, install MariaDB:
1 |
sudo yum install MariaDB-server |
MariaDB Service
CentOS uses systemd as the init system. The MariaDB service is managed by systemd. This service determines the MariaDB execution status. Run the following command to start the MariaDB daemon:
1 |
sudo systemctl start mariadb |
If the service was started successfully, it won’t show any output. To verify, we can check the service status:
1 |
sudo systemctl status mariadb |
Next, we need to ensure that MariaDB starts at boot. Otherwise, the service has to be manually started every time the system reboots:
1 |
sudo systemctl enable mariadb |
Securing MariaDB
Once MariaDB is up and running, we need to perform the initial configuration. MariaDB comes with a security script. It changes some of the default settings for better security. First, launch the security script:
1 |
sudo mariadb_secure_installation |
Every single step of the script comes with an explanation. The first step will ask for the MariaDB root password. Assuming it’s a fresh installation, there’s no root password configured. Press Enter to go to the next step.
If there’s no root password, the script will prompt you to set a new root password. The anonymous user feature is for testing purposes. It allows anyone to log in to MariaDB without having access to any user account. If you’re installing MariaDB for testing purposes only, then it’s fine to keep it. Otherwise, enter y to remove anonymous users:
Similar to Linux, the root user holds the ultimate power over all MariaDB databases and system configurations. It’s a common practice to disable root for remote login. If it’s a local server, this is the protocol you should follow. However, if MariaDB is running on a remote server, then consider keeping the feature:
The test database is a built-in database that’s designed for testing only. It should be removed when implementing MariaDB into a production environment:
Finally, the script will ask to reload privilege tables. It will ensure that all the changes made so far will take into effect immediately:
The script should finish without any issue.
Testing MariaDB
The MariaDB installation and configuration are complete now. It is time to test it out. The testing should work fine if everything up to this step was performed properly.
For the test, we’ll be using the
mysqladmin tool that’s dedicated to running administrative commands. Run the following command:
1 |
mysqladmin -u root -p version |
Here, we’ve used two flags:
- -u: Signifies the user to connect to MariaDB
- -p: Signifies password for user authentication
This command will print out the MariaDB version along with a short report of the system.
Basic Usage
-
Accessing MariaDB shell
To directly interact with the MariaDB server, it comes with a shell of its own. Launch the MariaDB shell as the root user:
1 |
sudo mysql -u root -p |
-
Listing databases
The following SQL query will print all the databases on the current server:
1 |
SHOW DATABASES; |
-
Creating a new database
Next, the following SQL query will create a new database
demo_database:
1 |
CREATE DATABASE demo_database; |
-
Accessing database contents
In order to check the content of a database, change the active database to the desired one and run necessary SQL queries. Then, change the current database:
1 |
USE demo_database; |
We can add, remove, or print the tables in the database. For example, here’s how to check all the tables under the database:
1 |
SHOW TABLES; |
-
Deleting a database
If a database is no longer needed, we can safely delete it. In MySQL/MariaDB terminology, deleting a database is called dropping. To drop the database “demo_database”, run the following command:
1 |
DROP DATABASE demo_database; |
Final Thoughts
Voila! MariaDB installation is successful! MariaDB is now ready to be deployed in production.
As MariaDB is very similar to MySQL, all the MySQL knowledge you learned before is still valid. For those who are new to MySQL and MariaDB, here’s a detailed guide on some of the most basic functions of MySQL. It elaborates on various MySQL functions and usage. You can also check out how to create a MySQL user, grant various permissions and privileges, and delete it.
Happy computing!
- How to Deploy WordPress with Persistent Volume on Kubernetes Cluster - March 17, 2023
- Deploying Applications on Kubernetes Using Argo CD and GitOps - October 26, 2022
- Using Node.js Modules with npm and package.json: A Tutorial - October 6, 2022
- Using Ansible to Install and Configure WordPress with LAMP on Ubuntu - September 23, 2022
- Creating Views in the Django Web Application Framework - September 22, 2022