June 6, 2025
Tutorials

How to Install and Configure MariaDB on Debian 12

How to install MARIADB on Debian 12

MariaDB is widely used and an open-source alternative to MySQL. It is renowned for its scalability, fast performance, and ACID compliance. With the installation of MariaDB, users are able to create databases, manage users, and execute SQL queries seamlessly. The purpose to install MariaDB on Debian 12 is to build a powerful and dependable relational database management system (RDBMS). It serves as the main framework for storing, retrieving, and managing data for various applications.

The article’s outline is given below.

Let’s start the article with an installation.

How to Install MariaDB on Debian 12?

If you are working on web applications, CMS, or any other project that requires powerful database support, then having MariaDB will ensure that all your data needs are met. For installing MariaDB on Debian 12, first update the package index and then use the command “sudo apt install mariadb-server” to install the package.

Let’s start with the installable first.

Method 1: Using the Ubuntu Default Repository

To install MariaDB on Debian 12 using the Ubuntu default repository, follow the below instructions carefully:

Step 1: Update Package Index

To obtain the most recent data from the package index, users must update the system repository with the apt command:

sudo apt update

sudo apt update

Step 2: Install the mariadb-server Package

Now, perform the apt command to install the mariadb-server package with sudo privileges:

sudo apt install mariadb-server

sudo apt install mariadb-server

Step 3: Secure MariaDB Installation

After installing MariaDB, utilize the mysql_secure_installation script to limit server access and improve security. The script will walk users through a series of prompts to set some security options to confine the restrictions of the MariaDB install:

sudo mysql_secure_installation

sudo mysql_secure_installation

While executing the script, users must specify a password for the root user in the current database. If the user has not specified a password, simply enter NONE. The script will lead you through other options too:

sudo mysql_secure_installation

Step 4: Test/Verify MariaDB Installation

You can check if the installation was successful by logging into the MariaDB shell using the root user and typing in the root password:

sudo mysql -u root -p

sudo mysql -u root -p

Optional: Upgrade MariaDB on Debian 12

To upgrade/install the newest version of MariaDB on Debian 12, you must first update the system packages, then install the MariaDB APT repository, and last install the MariaDB 10.11 server/client. Then you will have to secure the installation of MariaDB and verify if the installation was successful.

sudo mariadb-upgrade

sudo mariadb-upgrade

Method 2: Using the MariaDB Repository

In order to install the newest release of MariaDB on Debian 12, it is advisable to go with the official MariaDB repository. To install MariaDB on Debian 12 using the MariaDB repository, carry out this procedure:

Step 1: Update Package list

Update the system packages list as described to make sure you are getting the latest edition available:

sudo apt update

sudo apt update

Step 2: Install Software Properties

At this stage, users are required to install the dependent package. This is necessary for adding the new repositories:

sudo apt install software-properties-common

sudo apt install software-properties-common

Step 3: Import the MariaDB GPG Key

MariaDB GPG keys are needed to check the maintenance for the integrity of the repository. After that, import the key by using the below command:

curl -LsS https://mariadb.org/mariadb_release_signing_key.asc | sudo gpg –dearmor -o /etc/apt/trusted.gpg.d/mariadb.gpg

curl -LsS https://mariadb.org/mariadb_release_signing_key.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mariadb.gpg

Step 4: Add the MariaDB Repository

After that, you may replace the system’s GPG key with the repository of the GPG key. Be sure to swap “10.11” for the version you’d like to use and add the rest of the information:

echo “deb [signed-by=/etc/apt/trusted.gpg.d/mariadb.gpg] https://mirror.mariadb.org/repo/10.11/debian $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/mariadb.list

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

Note: Users are able to edit in the line where the repository is placed, in case the version of debian being used has a different codename.

Step 5: Update Packages List

At this stage, you must update the packages’ index in order to install MariaDB from the newly added repository:

sudo apt update

sudo apt update

Step 6: Install MariaDB Server

Now, users are able to install MariaDB server and client packages as they become available in the official MariaDB repository:

sudo apt install mariadb-server mariadb-client

sudo apt install mariadb-server mariadb-client

Step 7: Secure Installation of MariaDB

In this step, set a root password. The script will also question you for the following security options:

sudo mysql_secure_installation

sudo mysql_secure_installation

Step 8: Verify Installation

Now, validate that MariaDB is in an active state and verify if its service is currently running using the following command:

sudo systemctl enable mariadb

sudo systemctl start mariadb

sudo systemctl status mariadb

Verify MariaDB service

Additionally, users may also use the following command to access MariaDB through the MySQL command line interface:

sudo mysql -u root -p

That is all.

How to Configure/Use MariaDB on Debian 12?

To manage MariaDB on Debian 12, it must first be installed. Then, complete the following steps:

Step 1: Access MariaDB

On the Ubuntu server, open the terminal and sign in to MariaDB by executing it as the root user. The prompt will ask for the root password that the users established during installation:

sudo mysql -u root -p

sudo mysql -u root -p

Step 2: Create a New Database

For adding te new user to named mysample_db database, the required instruction is CREATE DATABASE database_name. So, we’ll create a database (say “mysample_db”) by executing:

CREATE DATABASE mysample_db;

CREATE DATABASE mysample_db;

Step 3: Creating a User

With the creation of the user, we will also create associated debian_user and assign the password “1214”:

CREATE USER ‘debian_user’@’localhost’ IDENTIFIED BY ‘1214’;

CREATE USER 'debian_user'@'localhost' IDENTIFIED BY '1214';

Step 4: Grant Privileges to the User for the Database

Now, allow the user privileges to allocate “debian_user” on the “mysample_db” database set above.

GRANT ALL PRIVILEGES ON mydb.* TO ‘linux_user’@’localhost’;

GRANT ALL PRIVILEGES ON mydb.* TO 'linux_user'@'localhost';

Step 5: Create a Table in MariaDB

A table can be added to MariaDB with the command CREATE TABLE . But before that, we must use USE mysample_db to switch to the database. Let’s create debian_table with columns id and data:

USE mysample_db
CREATE TABLE debian_table (
id INT AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(255)
);

Create table in MariaDB

Finally, use DESCRIBE debian_table to list the columns that compose the table. It records users with regard to the columns, kinds, and other details of the tables:

DESCRIBE debian_table;

DESCRIBE debian_table;

Step 6: Apply Changes

To implement the above modifications, execute “FLUSH PRIVILEGES” as given below:

FLUSH PRIVILEGES;

FLUSH PRIVILEGES;

Step 7: Exit the MariaDB Shell

Users can also leave the MariaDB session by typing exit or CTL–D:

exit

exit

That is all from the configuration.

How to Uninstall/Remove MariaDB on Debian 12?

To remove MariaDB from Debian 12, the users can make use of the command “remove”:

sudo apt autoremove mariadb-server mariadb-client –purge -y # For Removing Packages
sudo add-apt-repository -r ‘deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.11/debian’ # For Removing Repository

Uninstall/remove MariaDB

This command will delete the server as well as the client applications of MariaDB.

Conclusion

To install MariaDB on Debian 12, update the package index and install the mariadb-server package using the “sudo apt install mariadb-server” command. To secure the system after installation, the script mysql_secure_installation should be executed. To seamlessly integrate with the system, obtain and configure the MariaDB repository before proceeding to install the mariadb-server and mariadb-client packages.

To access/start MariaDB as a new user, execute the command mysql -u myuser -p, and after providing the corresponding password, users will have the ability to manage tables, modify data, and execute SQL queries within their database.

Frequently Asked Questions

MariaDB is a free, open-source relational database management system, often used as a drop-in replacement for MySQL.
Run sudo apt update to refresh the list of available packages from Debian repositories.
Use the command sudo apt install mariadb-server to install the MariaDB server and client.
Run mariadb --version or check the service status with sudo systemctl status mariadb.
Use sudo systemctl start mariadb to start the service.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video