DebianDebian Based

How To Install MariaDB on Debian 12

Install MariaDB on Debian 12

In this tutorial, we will show you how to install MariaDB on Debian 12. For those of you who didn’t know, MariaDB is a robust and widely-used open-source database management system. Offering high performance, scalability, and advanced features, it has become a popular choice for developers and enterprises alike.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MariaDB database on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for MariaDB.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install MariaDB on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install apt-transport-https lsb-release ca-certificates

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing MariaDB on Debian 12.

To install the latest stable version of MariaDB, we’ll add the official MariaDB repository to our system:


Make the downloaded file executable:

chmod +x mariadb_repo_setup

Run the setup file:

sudo ./mariadb_repo_setup

The setup script will configure the repository and import the repository key.

After adding the MariaDB repository, we need to update the repositories once more and to install the MariaDB server package, execute the following command:

sudo apt install mariadb-server

During the installation, you will be prompted to enter your password. Choose a strong password and keep it secure.

After the installation is complete, start the MariaDB service using the following command:

sudo systemctl start mariadb

Step 3. Secure the MariaDB installation.

To improve the default security settings, MariaDB provides a security script. Run the script and follow the prompts to enhance your installation’s security:

sudo mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

Step 4. Basic MariaDB Configuration.

Now that MariaDB is installed, let’s perform some basic configuration tasks. To access the MariaDB command-line interface as the root user, use the following command:

sudo mysql -u root -p

To create a new user, execute the following command in the MariaDB shell:

CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';

Next, we’ll grant the necessary privileges to the newly created user:

GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;

Step 5. Additional Considerations.

To optimize your MariaDB installation and ensure its stability and security, consider the following additional considerations:

  • Configuring MariaDB for production environments:

For production environments, it’s important to fine-tune MariaDB for optimal performance and security. Review the official MariaDB documentation and explore advanced configuration options to suit your specific requirements.

  • Backing up MariaDB databases:

Regularly backing up your databases is crucial to prevent data loss. Consider implementing a backup strategy that includes automated backups and offsite storage. Refer to the MariaDB documentation for comprehensive guidance on database backup and recovery procedures.

Congratulations! You have successfully installed MariaDB. Thanks for using this tutorial for installing the latest version of the MariaDB database on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official MariaDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button