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

MariaDB is an open-source relational database management system (RDBMS) that is a fork of MySQL. It is designed to replace MySQL, offering many of the same features and benefits with additional enhancements.

Using MariaDB offers many advantages, such as:

  • High performance and scalability
  • Advanced data types and storage engines
  • Improved security features
  • Strong community support and active development
  • Compatibility with existing MySQL applications and tools
  • Flexibility for customization and integration with other systems.

MariaDB also has several features, such as:

  • SQL (Structured Query Language) support
  • ACID (Atomicity, Consistency, Isolation, Durability) transactions
  • Stored procedures, triggers, and views
  • Replication and clustering
  • Full-text search and spatial data
  • Data encryption and role-based access control.

This guide will demonstrate how to set up the most recent versions of MariaDB on Debian 11 Bullseye and Debian 10 Buster by utilizing the official MariaDB.org repository. It includes instructions for long-term releases (e.g., 10.5 and 10.6) and short-term releases (e.g., 10.7, 10.8, 10.9, and the latest release, 10.10).

Step 1: Update Debian

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

sudo apt update

As an optional step, you can list the updates for those who want to review them or are curious about what is available to update. This can be useful if you have a specific package you wish to hold back from updating; you can use the apt-hold command.

apt --list upgradable

Continue by upgrading any outdated packages using the command provided.

sudo apt upgrade

Step 2: Install Dependencies

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 Repository

This section covers importing the Long-term Support (LTS) branches, which are recommended for production use. The 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, first, 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.

Option 1: Import MariaDB 10.5 (Long-term release)

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

Option 2: Import MariaDB 10.6 (Long-term release)

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

Option 3: Import MariaDB 10.7 (Short-term release)

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

Option 4: Import MariaDB 10.8 (Short-term release)

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

Option 5: Import MariaDB 10.9 (Short term release)

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

Option 6: Import MariaDB 10.10 (Short-term release) – Latest Release

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

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

sudo apt update

Step 4: Install MariaDB

With the repository and GPG key properly configured, proceed to install the MariaDB client and server packages. This can be done using the command provided.

sudo apt install mariadb-server mariadb-client -y

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

mariadb --version

Example output with MariaDB 10.10 installed:

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

Step 5: Enable MariaDB Service

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

systemctl status mariadb

Example:

With the installation of MariaDB completed, you can check the status of the database software by executing the systemctl command provided.

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

Step 6: Run MariaDB Security Script

When installing a new version of MariaDB, it is a common practice in the industry to consider the default settings weak and potentially pose a security risk. It is highly recommended to run the installation security script during the MariaDB installation process to address this concern. This script will help to secure the installation and prevent potential intrusion or exploitation by malicious actors.

To begin, use the command provided to run the mysql_secure_installation script.

sudo mysql_secure_installation

After running the mysql_secure_installation script, the next step is configuring the settings by setting a root password, disabling remote access from external sources, removing anonymous user accounts, and deleting the test database.

Example:

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 & Tips

Run MariaDB Database Tables Upgrade Tool

For users who have upgraded from an earlier version of MariaDB, such as from 10.5 to 10.10, it is recommended to use the steps provided and run the tool designed to check and fix any issues with the version upgrade. To start the upgrade process, or check the status of the database tables, use the command provided.

sudo mariadb-upgrade

Example output:

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 is recommended to run a command to check for and fix any issues with the version upgrade, regardless of whether or not an upgrade has been performed. As demonstrated in the previous example, if the command has already been executed, it will indicate it has been completed. If not, the command will provide a detailed list of tables that will be checked and updated for compatibility with MariaDB.

Remove MariaDB

To remove MariaDB altogether, execute the following command.

sudo apt autoremove mariadb-server mariadb-client --purge

It is important to note that the command provided will completely remove MariaDB and all associated data, including all databases. If you wish to keep this data, do not include the –purge flag in the command.

Finally, use the following command to remove the repository and GPG key.

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

Conclusion

In brief, this guide has presented a comprehensive guide on installing various versions of MariaDB on Debian 11 Bullseye and Debian 10 Buster using the official MariaDB.org repository. The instructions provided in the guide are easy to follow and will help users successfully install and use MariaDB on their Debian systems.

Share to...