HOW TO INSTALL MARIADB ON DEBIAN
Enjoying this content? Subscribe to the Channel!
Mastering MariaDB Installation on Debian 12: A Step-by-Step Guide
Welcome back to Darren’s Tech Tutorials!
If you’re building applications, managing data, or setting up a robust web server stack (like LAMP or LEMP), you need a reliable database. MariaDB is the powerful, open-source relational database that has become the preferred choice for many professionals, serving as a drop-in replacement for MySQL.
In this tutorial, we are going to walk through the incredibly straightforward process of installing MariaDB Server on Debian 12 (specifically tested on 12.5, but fully compatible with all Debian 12 systems). We’ll cover everything from system preparation to locking down your new installation with essential security measures.
Let’s dive in!
Prerequisites
Before we start tinkering, make sure you have the following:
- A running instance of Debian 12.
- Internet connectivity.
- Access to a user account with
sudoprivileges (or root access).
Step 1: Prepare and Update Your Debian System
The first rule of Linux installation is always ensuring your system is up-to-date. This updates your local package lists and ensures you are applying any outstanding security patches before installing new software.
Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade
Wait for the process to complete. This ensures we have the latest repositories ready for the MariaDB package.
Step 2: Verify Package Availability (Optional Check)
It’s always helpful to confirm exactly which package version we are about to install. You can use the apt show command to inspect the package details directly from the Debian repositories:
sudo apt show mariadb-server
This command will output detailed information about the package, including its version number and dependencies, confirming that the MariaDB server package is available for installation.
Step 3: Install MariaDB Server
Now for the main event! Installing MariaDB is handled efficiently by the Debian package manager, apt. We will use the -y flag to automatically confirm the installation and any dependencies required.
Run the installation command:
sudo apt install mariadb-server -y
Debian will now fetch the necessary files and install the MariaDB service. Once completed, the MariaDB server service is usually started automatically in the background.
Step 4: Secure the Installation
This step is critically important. After installing any database server, you must immediately secure it. MariaDB provides a helpful script that handles this for you: mariadb-secure-installation.
Run the security script:
sudo mariadb-secure-installation
The script will walk you through several prompts. Here is what you need to do:
- Enter current password for root: Since this is a fresh Debian installation, simply press Enter (the root database user does not have a password yet).
- Set root password? Type
Yand press Enter. Choose a strong, complex password. - Remove anonymous users? Type
Y. This prevents anonymous users from connecting to the database. - Disallow root login remotely? Type
Y. This is a strong security measure, forcing root database access only from the local machine. - Remove test database and access to it? Type
Y. The test database is unnecessary for production. - Reload privilege tables now? Type
Y. This applies your new security settings immediately.
Congratulations, your database server is now significantly more secure!
Step 5: Verify the MariaDB Service Status
Even though the server starts automatically, it’s good practice to verify that the service is running correctly using systemctl:
sudo systemctl status mariadb
You should see output indicating the service is active (running), typically highlighted in green. If it’s not running, you can manually start it using sudo systemctl start mariadb.
Step 6: Test Your Database Connection
The final step is to log into the MariaDB shell and confirm you can interact with the server using the root user credentials you just set up.
To log in as the root database user:
sudo mariadb
You will immediately be dropped into the MariaDB prompt, usually showing MariaDB [(none)]>.
You are now successfully connected! You can exit the shell by typing exit; and pressing Enter.
Conclusion: Ready to Build!
That’s all there is to it! In just a few quick steps, you have successfully installed and secured the powerful MariaDB database server on your Debian 12 machine. This foundation is essential for deploying countless web applications, content management systems, and custom projects.
Now that you have your database running, the real fun begins! Start exploring database creation, user management, and data manipulation.
If this tutorial helped you get set up, please hit that Like button on the video, and don’t forget to Subscribe to Darren’s Tech Tutorials for more clear, actionable guides just like this one. See you in the next video!