MariaDB is an open-source relational database management system (RDBMS) that is fully compatible with MySQL. It is known for its reliability, performance, and scalability. Many Linux-based systems, including servers and development environments, rely on MariaDB to manage databases.

In this article, we’ll walk you through how to install MariaDB on various Linux distributions, including Ubuntu, Debian, CentOS, and RHEL.
Prerequisites
Before beginning the installation, make sure your system meets the following requirements:
- A Linux machine (Ubuntu, Debian, CentOS, RHEL, etc.).
- Root or sudo access to install packages.
- An active internet connection to download the necessary packages.
Install MariaDB on Various Linux Distributions
The installation of MariaDB can vary depending on the Linux distribution you’re using. The primary differences will be in the package manager used (such as apt
for Ubuntu/Debian-based systems, or yum
/dnf
for CentOS/RHEL-based systems). Below, we’ll go into the specifics for each distribution.
Install MariaDB on Ubuntu/Debian
- Update the Package Index
The first step in the installation process is to update the package index on your system, ensuring you have the latest list of available packages. Open a terminal and run:
sudo apt update
- Install MariaDB Server
Now, install the MariaDB server package. This will install the MariaDB server and its dependencies.
sudo apt install mariadb-server
- Secure the MariaDB Installation
Once the installation is complete, it’s important to secure your MariaDB server. The mysql_secure_installation
script will guide you through setting a root password, removing insecure default settings, and improving security.
sudo mysql_secure_installation
Follow the on-screen prompts to:
- Set a root password.
- Remove test databases and anonymous users.
- Disable remote root login (for added security).
- Start and Enable MariaDB
Next, start the MariaDB service and enable it to start automatically on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
- Verify the Installation
To ensure that MariaDB is running correctly, you can check its status with the following command:
sudo systemctl status mariadb
To log into MariaDB and start using it, type:
sudo mysql -u root -p
You’ll be prompted to enter the root password you set earlier.
Check Out | How to Install MySQL on a Linux Server
Install MariaDB on CentOS/RHEL
- Install MariaDB Server
On CentOS or RHEL-based systems, use the following command to install MariaDB. The yum
package manager is typically used on older versions of CentOS/RHEL, and dnf
is used on newer versions.
sudo yum install mariadb-server # For CentOS/RHEL 7 and older
sudo dnf install mariadb-server # For CentOS/RHEL 8 and newer
- Start and Enable MariaDB
Once the installation is complete, start the MariaDB service and enable it to start on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
- Secure the MariaDB Installation
Run the mysql_secure_installation
script to secure your MariaDB server by setting a root password and adjusting security settings.
sudo mysql_secure_installation
- Verify the Installation
To verify that the MariaDB service is running, check its status:
sudo systemctl status mariadb
To log into MariaDB, use the following command:
sudo mysql -u root -p
Common Configuration Tasks After Installation
Once MariaDB is installed, there are a few important tasks to configure your system and start managing databases:
- Creating and Managing Databases
To create a new database, log into MariaDB and use the following command:
CREATE DATABASE mydatabase;
To manage users, create a new user and grant them privileges:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
- Configuring Remote Access
By default, MariaDB only allows connections from the localhost. To enable remote access, modify the MariaDB configuration file (/etc/mysql/mariadb.conf.d/50-server.cnf
or /etc/my.cnf
), and comment out or change the bind-address
to 0.0.0.0
:
bind-address = 0.0.0.0
After saving the file, restart MariaDB:
sudo systemctl restart mariadb
- Backing Up and Restoring Databases
To back up a database, use the mysqldump
command:
mysqldump -u root -p mydatabase > mydatabase_backup.sql
To restore a database, use the following command:
mysql -u root -p mydatabase < mydatabase_backup.sql
- Monitoring MariaDB Performance
You can monitor MariaDB’s performance using built-in tools like mysqladmin
and SHOW STATUS
:
mysqladmin -u root -p status
Or inside the MariaDB shell, run:
SHOW STATUS;
Conclusion
In this guide, we’ve walked through the installation of MariaDB on Ubuntu/Debian-based and CentOS/RHEL-based systems. MariaDB is a powerful and efficient relational database management system (RDBMS) that is ideal for use on Linux servers. Once installed, you can configure MariaDB to meet your needs, whether it’s for local or remote access, backups, or managing databases.
By following the steps outlined, you should have a fully functional MariaDB server on your Linux machine. For more advanced configurations, such as high availability or performance optimization, consult the official MariaDB documentation.