How to install MariaDB on Debian 11
In order to install MariaDB on Debian 11, the following steps are required:
- Update your Debian 11 installation.
- Install MariaDB.
- Customise the configuration according to your requirements.
- Create an additional admin user (optional).
- Check whether the installation was successful.
Why are MariaDB and Debian 11 a good fit?
In the MariaDB v. MySQL comparison, MariaDB has long since proven itself. This SQL server is known for being extremely robust, highly secure, and generally more flexible than the older database management system of the same origin. Designed as a direct drop-in replacement for MySQL, it can be used as a MySQL substitute within the LAMP stack (Linux, Apache, MySQL, and PHP, Python, or Perl) without significant adjustments being required. Debian has also been using MariaDB for quite some time and contains the necessary packages by default.
If you want to install MariaDB on Debian 10, you will find helpful instructions in our Digital Guide as well as some for setting up MariaDB on Debian 12. If you want to use MongoDB on Debian 10 instead, we will also guide you through all the necessary steps.
What requirements must be met?
There are only a few requirements that need to be met to install MariaDB installation on Debian 11. The first is that you need a server that Debian 11 is already installed on. Root access for this server is required and a suitable firewall should be set up and activated. As a rule, one CPU core is sufficient. In addition, at least 512 megabytes of RAM and 1 gigabyte of hard disk space are required.
- Cost-effective vCPUs and powerful dedicated cores
- Flexibility with no minimum contract
- 24/7 expert support included
How to install MariaDB on Debian 11 step by step
The following sections show you step by step how to install MariaDB on Debian 11.
Step 1: Update the package index
Before you start the actual installation, you should make sure that all your programs and Debian 11 itself are up to date. To do this, update the package index with these two apt
commands:
sudo apt update
sudo apt upgrade
bashOnce this is done, you can start installing MariaDB on Debian 11.
Step 2: Install MariaDB on Debian 11
Use the following command to install the package for MariaDB:
sudo apt install mariadb-server
bashOnce this process is complete, it means you have installed MariaDB on Debian 11, but no security precautions have yet been taken for your system. This part comes in the next step.
Step 3: Execute the security script
MariaDB offers its own security script for its newer versions. You can use this script to modify some default settings. The command to initiate the script is as follows:
sudo mysql_secure_installation
bashWhen you start the script, you’ll first be prompted to enter your root password for the database. Since you haven’t set this up yet, press [Enter] to skip this step for now. Then, you will be asked if you want to switch to authentication via unix_socket. Type [N] and press [Enter] to confirm.
You will be asked if you want to change your root password. However, this is not recommended for security reasons, so press [N] and [Enter] again. Answer the following questions with [Y] to remove anonymous users, the test database and root logins remotely.
Step 4: Set up an additional admin (optional)
The next step is optional but highly recommended for securing your system. In Debian 11, the MariaDB root user is authenticated using unix_socket instead of a password. Although this has some benefits, it can cause problems when external programs need admin rights. A solution is to create an additional admin user to complement the root account. Here are the steps to do this:
Open the MariaDB shell:
sudo mariadb -u root
bashNow create the new user. Change the username and password as required.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
sqlUse the ‘FLUSH PRIVILEGES’ command for security:
FLUSH PRIVILEGES;
sqlFinally, close the shell:
exit
bashStep 5: Check whether the installation was successful
Finally, check whether the installation of MariaDB on Debian 11 was a success. To do this, test the status with this command:
sudo systemctl status mariadb
bashIf MariaDB does not start automatically, use the following command:
sudo systemctl start mariadb
bashYou’re now free to use MariaDB.