How to Install MariaDB 11.x or 10.x on Debian 12, 11 or 10

MariaDB is a robust and efficient choice in relational database management systems. For Debian users, the ability to install MariaDB on Debian 12 Bookworm or the older stable releases of Debian 11 Bullseye or Debian 10 Buster can significantly enhance their database operations. This guide aims to simplify the installation process, focusing on the official MariaDB.org repository to ensure you get the latest and most secure versions.

Why Choose MariaDB?

  • Performance and Scalability: MariaDB is designed for high performance, ensuring smooth operations even with large datasets.
  • Advanced Features: Beyond the standard SQL support, MariaDB offers advanced data types, storage engines, and ACID transactions, ensuring data integrity and reliability.
  • Enhanced Security: With features like data encryption and role-based access control, MariaDB prioritizes the security of your data.
  • Community and Development: Being open-source, MariaDB boasts a vibrant community that actively contributes to its development, ensuring continuous improvements and updates.
  • MySQL Compatibility: MariaDB is not just a fork of MySQL but a worthy successor, offering compatibility with existing MySQL applications and tools while introducing additional benefits.
  • Customization and Integration: The flexibility of MariaDB allows for easy customization and seamless integration with other systems.

Key Features of MariaDB:

  • SQL Support: MariaDB fully supports Structured Query Language, the standard language for relational database management.
  • ACID Transactions: Ensuring data reliability and integrity through Atomicity, Consistency, Isolation, and Durability.
  • Advanced Database Operations: From stored procedures, triggers, and views to replication and clustering, MariaDB offers a comprehensive suite of features.
  • Search and Data Security: Features like full-text search, spatial data, and advanced encryption make MariaDB versatile and secure.

As we delve deeper into this guide, you’ll gain insights into setting up MariaDB on your Debian system, ensuring a seamless database management experience.

Import MariaDB.org APT Repository on Debian 12, 11, or 10

Step 1: Update Debian Packages Before Installing MariaDB

Begin by updating your system to make sure all current packages are current.

sudo apt update

Continue by upgrading any outdated packages using the command provided.

sudo apt upgrade

Step 2: Install Initial Required Packages For MariaDB Installation

The initial step is to install the necessary dependencies for the installation. Execute the command below in your terminal.

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y

Step 3: Import MariaDB APT Repository on Debian

This section covers importing the Long-term Support (LTS) branches recommended for production use. A short-term release is an option for those who prefer using the latest versions of MariaDB on a Content Management System (CMS) like WordPress and don’t mind upgrading their versions every 6-12 months.

Before installing, import the GPG key to verify the MariaDB packages using the command below.

curl -fsSL http://mirror.mariadb.org/PublicKey_v2 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg > /dev/null

After importing the GPG key, the next step is to import the repository. The commands will work with Debian 11 and Debian 10 distribution releases.

10.5 (Long-term release) EOL

End-of-life: 24 Jun 2025

echo "deb [signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.5/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

10.6 (Long-term release)

End-of-life: 06 Jul 2026

echo "deb [signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.6/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

10.11 (Long-Term release)

End-of-life: 16 Feb 2028

echo "deb [signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.11/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

11.0 (Short-term Release) EOL: 06 Jun 2024

End-of-life: 06 Jun 2024

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.0/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

11.1 (Short-term Release)

End-of-life: 21 Aug 2024

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.1/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

11.2 (Short-term Release)

End-of-life: 21 Nov 2024

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/11.2/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

At the time of this article, there remains no long-term release version of the MariaDB 11.x release. Short-term releases are supported for one year.

The dates for the end of support for the versions are added, for production always use an LTS version unless you are prepared to handle the updates of changing to a newer release.

After importing the repository, update your APT repository using the command provided.

sudo apt update

Install MariaDB on Debian 12, 11, or 10

Step 1: Proceed to Install MariaDB on Debian After MariaDB.org Setup

Install the MariaDB client and server packages with the repository and GPG key properly configured. Use the following command to install MariaDB:

sudo apt install mariadb-server mariadb-client

Step 2: Confirm MariaDB Installation

Confirm the installation of MariaDB by checking the version and build.

mariadb --version

Example output with MariaDB 10.10 installed:

mariadb  Ver x.x Distrib x.x.x-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

Enable MariaDB Service on Debian 12, 11 or 10

Step 1: Verify MariaDB Service Status

With the installation of MariaDB complete, you can check the status of the database software by using the following systemctl command.

systemctl status mariadb
Screenshot of 'systemctl status mariadb' command output in terminal for Debian Linux.Pin
Command output screenshot: Checking MariaDB’s status on Debian using systemctl.

If, by chance, you haven’t started the service, use the following command to enable it both immediately and upon system reboot:

sudo systemctl enable mariadb --now

Step 2: MariaDB Systemd Service Commands

Below are the most common systemd service commands you need to note when working with MariaDB on your Debian system.

Start MariaDB:

sudo systemctl start mariadb

Stop MariaDB:

sudo systemctl stop mariadb

Enable MariaDB on system startup:

sudo systemctl enable mariadb

Disable MariaDB on system startup:

sudo systemctl disable mariadb

Restart the MariaDB service:

sudo systemctl restart mariadb

Post-Installation: Securing MariaDB on Debian 12, 11, or 10

After installing a fresh version of MariaDB, it’s vital to understand that the out-of-the-box settings might not offer robust security. Thus, seasoned database administrators often suggest tightening these settings to prevent vulnerabilities.

Running the Security Script

MariaDB provides a handy script called mysql_secure_installation to help administrators secure their installations. Executing this script is not just a best practice; it’s a proactive step in fortifying your database against potential threats.

Execute the following command to run the script:

sudo mysql_secure_installation

or

sudo mariadb-secure-installation

Configuring MariaDB for Enhanced Security

Upon initiating the mysql_secure_installation script, you’ll be guided through several steps to enhance the database’s security:

  • Setting a Root Password: Choosing a strong and unique password for the root user is imperative to ensure that only authorized personnel can make critical changes.
  • Restricting Remote Access: Denying direct root logins from external sources is good for added security. This minimizes the risk of unauthorized access attempts from remote locations.
  • Removing Anonymous Users: MariaDB, by default, has anonymous user accounts that anyone can use to log in. Eliminating these accounts adds an extra layer of security, ensuring that only known and designated users can access the system.
  • Deleting the Test Database: MariaDB has a test database accessible to everyone. While it might be helpful for initial tests, removing it in a production environment is safer to avoid any potential misuse.

By diligently following these steps, you’ll set up a robust line of defense for your MariaDB installation, ensuring its longevity and integrity in your tech stack.

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.
Enabled successfully!
Reloading privilege tables..
 ... Success!


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.
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


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
production environment.

Remove anonymous users? [Y/n] Y <---- Type Y then press the ENTER KEY.
 ... Success!

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.
 ... Success!

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...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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.
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Additional Commands For MariaDB on Debian 12, 11, or 10

Running the MariaDB Database Tables Upgrade Tool

If you’ve transitioned from an older version of MariaDB, like moving from 10.5 to 10.10, it’s prudent to ensure the smooth functionality of your database tables. MariaDB offers a specialized tool, mariadb-upgrade, tailored to scrutinize and rectify any discrepancies that might arise due to the version transition.

Initiate the process or review the current status of your database tables by keying in:

sudo mariadb-upgrade

For instance, if you encounter output like:

This installation of MariaDB is already upgraded to 10.10.2-MariaDB.
There is no need to run mysql_upgrade again for 10.10.2-MariaDB.
You can use --force if you still want to run mysql_upgrade

It indicates that the upgrade tool has already done its job for the mentioned version. But even if you haven’t executed an upgrade recently, running this tool is still a wise decision. It meticulously lists and updates tables to ensure they remain compatible with the current MariaDB installation.

Uninstalling MariaDB from Debian

There might be circumstances where you wish to uninstall MariaDB from your Debian system. If that’s your chosen course, it’s essential to do so cleanly to prevent lingering files or configurations.

Start by removing the core MariaDB components:

sudo apt auto mariadb-server mariadb-client

Then, to purge all references to MariaDB, delete the associated repository and GPG key.

sudo rm /etc/apt/sources.list.d/mariadb.list /usr/share/keyrings/mariadb.gpg

Conclusion

In conclusion, this article provided a comprehensive guide on enhancing your Debian system with the latest MariaDB stable builds from the official mariadb.org apt repository. We imported the repository and installed a customized MariaDB build, whether in the 10.x or 11.x release series.

Furthermore, we delved into essential service commands that empower you to manage your MariaDB service effectively. The guide also highlighted the steps to upgrade your database seamlessly after installing a newer version of MariaDB. For those needing to revert or make changes, we covered the process to remove both MariaDB and its imported apt repository. Armed with this knowledge, you’re now equipped to confidently manage, upgrade, and optimize your MariaDB installations on Debian.

Leave a Comment


Your Mastodon Instance
Share to...