Table of Contents[Hide][Show]
MariaDB is a popular open-source relational database management system (RDBMS) that is a fork of MySQL. It is widely used for its performance, scalability, and robust feature set. Whether you’re setting up a new server, migrating from MySQL, or just exploring new database options, knowing how to install MariaDB on Linux is an essential skill for any system administrator or developer.
In this article, we will walk you through the process of installing MariaDB on various Linux distributions, including Ubuntu, Debian, CentOS, and Fedora. We will also cover basic configuration steps, securing your installation, and some common troubleshooting tips.
By the end of this guide, you will have a fully functional MariaDB server running on your Linux machine.
Why Should I Use MariaDB?
MySQL has long been one of the most widely used and popular relational database management systems (RDBMS), often serving as the go-to choice for developers worldwide. However, in 2008, MySQL was acquired by Sun Microsystems, which was later purchased by Oracle Corporation. This acquisition led to concerns about MySQL’s future as an open-source project, as Oracle’s ownership shifted its trajectory away from being fully open-source.
Enter MariaDB. MariaDB is a community-driven, open-source RDBMS that was created as a fork of MySQL by its original co-founder, Michael “Monty” Widenius, along with other core developers and community members. MariaDB is sponsored by Monty Program AB and the MariaDB Foundation, ensuring its development remains independent, transparent, and truly open-source.
Michael “Monty” Widenius, along with David Axmark and Allan Larsson, originally created MySQL. After the acquisition by Oracle, Monty founded Monty Program AB, which now plays a pivotal role in the development of MariaDB. The MariaDB Foundation oversees the project, ensuring it remains free, open, and aligned with the needs of its users.
Here are some compelling reasons to choose MariaDB:
- Truly Open Source: MariaDB is developed under an open-source license, ensuring transparency, community involvement, and freedom from vendor lock-in.
- Backed by the Original MySQL Developers: With Monty Widenius and other core MySQL developers leading its development, MariaDB benefits from their deep expertise and commitment to innovation.
- Enhanced Features and Performance: MariaDB includes numerous improvements over MySQL, such as better performance, additional storage engines, and advanced features.
- Compatibility with MySQL: MariaDB is fully compatible with MySQL, making it easy to migrate existing MySQL applications without significant changes.
- Active Community and Foundation Support: The MariaDB Foundation ensures the project remains community-driven and focused on user needs.
In short, MariaDB offers a reliable, high-performance, and truly open-source alternative to MySQL, backed by the original creators of MySQL and a vibrant community. Whether you’re looking for enhanced features, better performance, or a commitment to open-source principles, MariaDB is an excellent choice for your database needs.
Who Uses MariaDB?
MariaDB is widely adopted by organizations, Linux distributions, and major websites due to its performance, reliability, and open-source flexibility. Many have migrated from MySQL to MariaDB, benefiting from its enhanced features and seamless compatibility.
Notable Users of MariaDB:
Here’s the organized table:
Websites and Platforms | Linux Distributions | Other Organizations |
---|---|---|
OpenSUSE | OLX | |
Amazon Web Services (AWS) | Fedora | Nimbuzz |
Arch Linux | SlashGear | |
Mozilla Corporation | Red Hat Enterprise Linux (RHEL 7+) | |
Wikipedia | Manjaro | |
Mageia | ||
Debian | ||
The Chakra Project | ||
Gentoo | ||
OpenBSD |
These entities trust MariaDB for its scalability, high performance, and active community support, making it a preferred choice for modern database management.
How to Install MariaDB on Linux
Introduction to MariaDB
MariaDB was created by the original developers of MySQL after concerns arose over its acquisition by Oracle. It is fully compatible with MySQL, meaning that most applications that work with MySQL will also work with MariaDB without any modifications. MariaDB offers several enhancements over MySQL, including improved performance, new storage engines, and additional features.
MariaDB is widely used in web applications, particularly those built on the LAMP (Linux, Apache, MySQL, PHP) stack. It is also a popular choice for cloud-based applications and is supported by major cloud providers like AWS, Google Cloud, and Azure.
Prerequisites
Before we dive into the installation process, there are a few prerequisites you should be aware of:
- A Linux-based operating system: This guide covers Ubuntu, Debian, CentOS, and Fedora, but the steps are similar for other distributions.
- Root or sudo access: You will need administrative privileges to install and configure MariaDB.
- Basic knowledge of the Linux command line: Familiarity with basic commands and text editors like
nano
orvi
will be helpful. - An active internet connection: You will need to download packages from the internet.
How to Install MariaDB on Linux
The installation process for MariaDB varies slightly depending on the Linux distribution you are using. Below, we will cover the steps for Ubuntu/Debian and CentOS/Fedora.
Installing MariaDB on Ubuntu and Debian
Ubuntu and Debian are two of the most popular Debian-based Linux distributions. The following steps will guide you through the installation of MariaDB on these systems.
Step 1: Update the Package List
Before installing any new software, it’s a good idea to update your package list to ensure you have the latest versions of all packages.
sudo apt update
Step 2: Install MariaDB
Once the package list is updated, you can install MariaDB using the following command:
sudo apt install mariadb-server
This command will install MariaDB along with any necessary dependencies.
Step 3: Start and Enable MariaDB Service
After the installation is complete, you need to start the MariaDB service and enable it to start on boot.
sudo systemctl start mariadb sudo systemctl enable mariadb
Step 4: Verify the Installation
To verify that MariaDB has been installed correctly and is running, you can use the following command:
sudo systemctl status mariadb
You should see an output indicating that the service is active and running.
Installing MariaDB on CentOS and Fedora
CentOS and Fedora are popular RPM-based Linux distributions. The following steps will guide you through the installation of MariaDB on these systems.
Step 1: Update the Package List
As with Ubuntu and Debian, it’s a good idea to update your package list before installing new software.
sudo yum update
Step 2: Install MariaDB
On CentOS and Fedora, you can install MariaDB using the following command:
sudo yum install mariadb-server
This command will install MariaDB along with any necessary dependencies.
Step 3: Start and Enable MariaDB Service
After the installation is complete, you need to start the MariaDB service and enable it to start on boot.
sudo systemctl start mariadb sudo systemctl enable mariadb
Step 4: Verify the Installation
To verify that MariaDB has been installed correctly and is running, you can use the following command:
sudo systemctl status mariadb
You should see an output indicating that the service is active and running.
How to Configure MariaDB on Linux
Once MariaDB is installed, you may want to perform some basic configuration to optimize its performance and tailor it to your needs.
Configuring the MariaDB Server
The main configuration file for MariaDB is located at /etc/mysql/my.cnf
on Debian-based systems and /etc/my.cnf
on RPM-based systems. You can edit this file to change various settings, such as the bind address, port, and buffer sizes.
For example, to change the bind address (the IP address that MariaDB listens on), you can edit the my.cnf
file and modify the following line:
bind-address = 127.0.0.1
Change 127.0.0.1
to the IP address you want MariaDB to listen on, or 0.0.0.0
to listen on all interfaces.
Creating a New Database and User
To create a new database and user, you can use the MariaDB command-line client. First, log in to the MariaDB server as the root user:
sudo mysql -u root -p
You will be prompted to enter the root password. Once logged in, you can create a new database:
CREATE DATABASE mydatabase;
Next, create a new user and grant them privileges on the database:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES;
Replace mydatabase
, myuser
, and mypassword
with your desired database name, username, and password.
Securing MariaDB
Securing your MariaDB installation is crucial to protect your data from unauthorized access. MariaDB includes a security script that helps you secure your installation.
The mysql_secure_installation
script helps secure your MariaDB installation by configuring important security settings. Follow these steps:
Run the Security Script
Execute the following command in your terminal:
sudo mysql_secure_installation
Set a Root Password
If you haven’t set a root password yet, the script will prompt you to do so.
Prompt:
Enter current password for root (enter for none):
If no password is set, press Enter. Otherwise, enter the existing root password.
If authentication is set to unix_socket, you may see:
Switch to unix_socket authentication [Y/n]
Press Y (recommended) or n to keep the current method.
The script will then ask if you want to set a new root password:
Set root password? [Y/n]
Type Y and enter a strong password when prompted:
New password: ********
Re-enter new password: ********
Output:
Password updated successfully!
Remove Anonymous Users
The script will ask if you want to remove anonymous users:
Remove anonymous users? [Y/n]
Press Y to enhance security.
Output:
Success!
Disallow Remote Root Login
To prevent unauthorized remote root access, the script asks:
Disallow root login remotely? [Y/n]
Press Y (recommended).
Output:
Success!
Remove the Test Database
MariaDB comes with a default test database that should be removed:
Remove test database and access to it? [Y/n]
Press Y.
Output:
Dropping test database...
Success!
Reload Privilege Tables
To apply changes, the script will prompt:
Reload privilege tables now? [Y/n]
Press Y.
Output:
Success!
All done!
Follow the prompts and make the appropriate choices based on your security requirements.
Configuring Firewall Rules
If you have a firewall enabled, you need to allow traffic on the MariaDB port (default is 3306). On Ubuntu/Debian, you can use ufw
to allow traffic:
sudo ufw allow 3306/tcp
On CentOS/Fedora, you can use firewalld
:
sudo firewall-cmd --permanent --add-port=3306/tcp sudo firewall-cmd --reload
Common Troubleshooting Tips
While installing and configuring MariaDB, you may encounter some common issues. Here are a few troubleshooting tips:
MariaDB Service Fails to Start
If the MariaDB service fails to start, check the error logs for more information. The logs are typically located at /var/log/mysql/error.log
on Debian-based systems and /var/log/mariadb/mariadb.log
on RPM-based systems.
Connection Refused
If you are unable to connect to the MariaDB server, ensure that the server is running and that the bind address is correctly configured. Also, check your firewall rules to ensure that traffic on port 3306 is allowed.
Forgotten Root Password
If you forget the root password, you can reset it by stopping the MariaDB service and restarting it with the --skip-grant-tables
option. This allows you to log in without a password and reset it.
sudo systemctl stop mariadb sudo mysqld_safe --skip-grant-tables & mysql -u root
Once logged in, you can reset the root password:
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
Replace newpassword
with your desired password. Then, restart the MariaDB service normally.
Conclusion
In this article, we have covered how to install MariaDB on Linux, including detailed steps for Ubuntu, Debian, CentOS, and Fedora. We also discussed basic configuration, securing your installation, and common troubleshooting tips.
MariaDB is a powerful and versatile database management system that is well-suited for a wide range of applications. By following this guide, you should now have a fully functional MariaDB server running on your Linux machine, ready to handle your data storage and retrieval needs.
Whether you’re a seasoned system administrator or a developer exploring new database options, knowing how to install MariaDB on Linux is a valuable skill that will serve you well in your projects. With its robust feature set and strong community support, MariaDB is an excellent choice for your database needs.