This guide will demonstrate how to install MariaDB on Ubuntu 24.04, 22.04, or 20.04 LTS Linux releases using the command-line terminal with the APT Package Manager.
MariaDB stands out as a robust and reliable database management system, widely recognized for its performance, security, and compatibility with MySQL. Originating as a fork of MySQL, MariaDB has evolved to offer a wealth of features that cater to a broad range of applications, from small-scale projects to enterprise-level deployments. Its commitment to open source and community-driven development ensures that MariaDB remains cutting-edge and accessible. Notable highlights include:
- Advanced Replication Capabilities: Ensures data consistency and high availability across multiple servers.
- Storage Engine Diversity: Supports a variety of storage engines, allowing customization for specific use cases.
- Comprehensive Security Features: Offers robust security measures, including encryption, to protect data integrity.
- Optimized Query Performance: Features advanced optimization techniques for fast and efficient data retrieval.
- Scalability and Flexibility: Easily scales to meet growing data demands while maintaining performance.
- Active Community Support: Benefits from a vibrant community that contributes to its continuous improvement.
- Wide Compatibility: Compatible with a broad range of programming languages and platforms.
- Ease of Migration: Simplifies the transition from MySQL, making it a hassle-free option for users looking to switch.
Transitioning seamlessly from a high-level overview to a practical walkthrough, this guide is structured to provide you with a straightforward, step-by-step process.
Let’s dive into the technical steps to get MariaDB up and running on your Ubuntu system.
Table of Contents
MariaDB Pre-Installation Steps on Ubuntu
Update Ubuntu Before MariaDB Installation
Before installing MariaDB, it’s crucial to update your Ubuntu system. This step ensures that all existing packages are current, minimizing potential conflicts.
Run the following command to update the package list:
sudo apt update
After updating the list, proceed to upgrade any outdated packages. This step is vital for system stability and security:
sudo apt upgrade
Install Initially Required Packages
MariaDB installation requires certain dependencies. These are essential packages that MariaDB needs to function correctly. Install them with the following command:
sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y
Import MariaDB APT Repository
The next step involves importing the MariaDB APT repository. This repository contains the MariaDB packages you’ll install. There are different branches available: Long-term support (LTS) branches, recommended for production environments due to their stability, and short-term releases, suitable for users who regularly update their systems, such as those running content management systems like WordPress.
Importing the GPG Key
First, import the GPG key to verify the authenticity of the MariaDB packages:
curl -fsSL http://mirror.mariadb.org/PublicKey_v2 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg > /dev/null
Select MariaDB Version Repository
Select the appropriate MariaDB version based on your requirements:
Option 1: MariaDB 10.5 (LTS)
End-of-life date: 24th June 2025.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.5/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Option 2: MariaDB 10.6 (LTS)
End-of-life date: July 2026.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.6/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Option 3: MariaDB 10.11 (LTS)
End-of-life date: February 2028.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.11/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Option 4: MariaDB 11.0 (Short-term release)
End-of-life date: June 2024.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.0/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Option 5: MariaDB 11.1 (Short-term release)
End-of-life date: August 2024.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.1/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Option 6: MariaDB 11.2 (Short-term release)
End-of-life date: November 2024.
echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.2/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list
Refresh APT Package Index After MariaDB Repository Import
Once you’ve chosen and imported the desired repository version, refresh your APT repository to recognize the new source:
sudo apt update
This step ensures that the system recognizes the newly added MariaDB repository and is ready for the installation process.
Install MariaDB 11.x or 10.x via APT Command
Install MariaDB Server and Client
To set up MariaDB on your system, you need to install both the server and client packages. This installation integrates the database server, which manages the data, and the client, which provides an interface to interact with the server.
Execute the following command to install these packages:
sudo apt install mariadb-server mariadb-client -y
Verifying MariaDB Installation
After installation, it’s important to confirm that MariaDB is correctly installed. Check the installed version and build of MariaDB using this command:
If the installation is successful, you will see an output similar to this:
mariadb Ver x.xx Distrib xx.xx.x-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Enable MariaDB Service
Checking MariaDB Service Status
Post-installation, verify the status of the MariaDB service. This command checks if MariaDB is active and running:
systemctl status mariadb
Starting MariaDB Service
While MariaDB typically activates automatically after installation, you can manually start it if needed:
sudo systemctl start mariadb
Stopping MariaDB Service
To stop the MariaDB service, use the following command:
sudo systemctl stop mariadb
Enabling MariaDB on System Startup
For MariaDB to start automatically upon system boot:
sudo systemctl enable mariadb
Disabling MariaDB on System Startup
To prevent MariaDB from starting automatically:
sudo systemctl disable mariadb
Restarting MariaDB Service
Restarting the service is often required after configuration changes. Use this command to restart MariaDB:
sudo systemctl restart mariadb
Run MariaDB Security Script on Ubuntu
Importance of Running the MariaDB Security Script
When setting up MariaDB, it’s essential to strengthen its default configurations, which are generally considered insecure. This step is crucial in safeguarding the database against unauthorized access and vulnerabilities. Running the
mysql_secure_installation script is a widely recognized industry practice during the MariaDB installation process. It enhances the security of your MariaDB installation and mitigates risks associated with potential malicious attacks.
Executing the Security Script
To initiate this security enhancement process, execute the
mysql_secure_installation script. This script performs several security-related operations, ensuring a more secure environment for your MariaDB installation:
Configuring Security Settings
After running the script, you will be guided through several steps to improve the security of your MariaDB installation:
- Setting the Root Password: You’ll be prompted to create a strong password for the root user of MariaDB. This step is critical as it prevents unauthorized database access.
- Disallowing Remote Root Access: The script will ask if you want to disable remote root logins, a recommended practice to limit access to local users only.
- Removing Anonymous User Accounts: These accounts are accessible without a password, posing a security risk. Removing them is a vital step in securing your database.
- Deleting the Test Database: MariaDB comes with a default test database accessible to anyone. Removing this database reduces potential points of entry for unauthorized users.
Following these steps significantly improves the security posture of your MariaDB installation on Ubuntu.
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):
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 <---- Type Y then press the ENTER KEY.
Reloading privilege tables..
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y <---- Type Y then press the ENTER KEY.
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
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
Remove anonymous users? [Y/n] Y <---- Type Y then press the ENTER KEY.
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 <---- Type Y then press the ENTER KEY.
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 <---- Type Y then press the ENTER KEY.
- Dropping test database...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y <---- Type Y then press the ENTER KEY.
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Managing MariaDB on Ubuntu
Run MariaDB Database Tables Upgrade Tool
If you’ve upgraded MariaDB to a newer version (e.g., from 10.5 to 10.10), ensuring your database tables are compatible with the new version is crucial. The
mariadb-upgrade tool is designed for this purpose. It checks and updates the tables to align with the upgraded version’s requirements.
To start this process or to check the current status of your database tables, run:
Running this command is advisable even if you believe the upgrade has been successful. The tool will confirm this in cases where it has already been executed. Otherwise, it will provide a detailed report on the tables examined and any necessary updates.
To completely remove MariaDB from your system, use the following command:
sudo apt autoremove mariadb-server mariadb-client --purge -y
Be aware that using the
--purge flag will delete not only MariaDB but also all associated database data. If you intend to retain the data, omit the
After removing MariaDB, it’s important also to remove the repository and GPG key to prevent any future updates from the MariaDB repository. This can be done with the following command:
sudo rm /etc/apt/sources.list.d/mariadb.list /usr/share/keyrings/mariadb.gpg
To wrap up, we’ve navigated through the essential steps for installing MariaDB, covering both the 11.x and 10.x versions, on Ubuntu 22.04 and 20.04 LTS. This guide has provided detailed insights and commands to ensure a smooth installation process, leveraging the official MariaDB.org repository. Whether you’re a novice or an experienced user, these instructions aim to make your experience with setting up and managing MariaDB on Ubuntu straightforward and hassle-free. As you move forward, remember to regularly check for updates and maintain your MariaDB installation to ensure optimal performance and security.