Overview
MariaDB is a robust, open-source relational database management system that originated as a fork of MySQL. It is designed to be compatible with MySQL and the SQL query language, while offering its own set of features. MariaDB is a reliable choice for data storage across various applications, from websites to enterprise-level systems, and supports multiple operating systems and programming languages, making it a preferred option for many developers.
This guide details the steps to install MariaDB on Debian versions 10, 11, and 12.
Installation Steps
Step 1 - System Update
- Begin by updating the system packages:
apt-get update -y
Step 2 - Install Dependencies
- Install the necessary dependencies with the following command:
apt-get install curl software-properties-common dirmngr gnupg2 -y
Step 3 - Add GPG Key
- Download and add the GPG key by running these commands:
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
bash mariadb_repo_setup --os-type=debian --os-version=buster --mariadb-server-version=11.3
Step 4 - Install MariaDB Repository Installation Package
- First, download the MariaDB repository installation package:
wget http://ftp.us.debian.org/debian/pool/main/r/readline5/libreadline5_5.2+dfsg-3+b13_amd64.deb
dpkg -i libreadline5_5.2+dfsg-3+b13_amd64.deb
apt-get update -y
Step 5 - Install MariaDB
- Install MariaDB server and client:
apt-get install mariadb-server mariadb-client -y
Step 6 - Enable MariaDB
- Start and enable MariaDB to run on boot:
systemctl start mariadb
systemctl enable mariadb
Step 7 - Verify MariaDB Installation
- Check the status of MariaDB to ensure it is active:
systemctl status mariadb
Step 8 - Secure MariaDB Installation
- Secure your MariaDB installation by setting a root password and adjusting security settings:
mysql_secure_installation
By default, the root password is empty. Press enter to continue, and then follow the prompts to set a new root password and answer all security-related questions with "y".
Access MariaDB with the new root password:
mariadb -u root -p
Additional Configurations
Create a Database
- To create a new database, use the following command (replace 'my_database' with your preferred name):
CREATE DATABASE my_database;
Create a User
- Create a new MariaDB user (replace 'username' and 'password' with your desired credentials):
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
Create a Table
- Select the database and create a table to store data:
USE my_database;
CREATE TABLE employees (id INT, name VARCHAR(20), surname VARCHAR(20));
- Verify the table creation:
SHOW TABLES;
- You should see such output:
Insert Data
- Insert data into the table:
INSERT INTO employees (id, name, surname) VALUES (1, 'John', 'Smith');
SELECT * FROM employees;
- The output should display the inserted data.