frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How to install MariaDB on Debian

Introduction

MariaDB is an open-source and freely licensed relational database management system created as a fork of MySQL. Despite some differences in product functionality, MariaDB is fully compatible with MySQL and the SQL query language. MariaDB provides reliable data storage for a variety of applications, from websites to enterprise systems. It supports many operating systems and popular programming languages, making it a popular choice for developers.

In this guide, you will learn how to install MariaDB on Debian (10, 11, 12 versions).

Installation guide

1. Update system

First, update system by running the following command:

apt-get update -y

2. Install the required dependencies

Run this command to install the required dependencies:

apt-get install curl software-properties-common dirmngr gnupg2 -y

3. Add the GPG key

Run these commands to download and add the GPG key:

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

4. Install the 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

Then run this command to install it:

dpkg -i libreadline5_5.2+dfsg-3+b13_amd64.deb

After that, repeat system update:

apt-get update -y

5. Install MariaDB

To install MariaDB, run this command:

apt-get install mariadb-server mariadb-client -y

6. Enable MariaDB

To start and then enable MariaDB, run these commands:

systemctl start mariadb
systemctl enable mariadb

7. Check MariaDB

To check if MariaDB is active, run the following command:

systemctl status mariadb

It will show you information about status of MariaDB on your server (including MariaDB version):

8. Secure MariaDB Installation

The default MariaDB installation is not secured, so we highly recommend you to set root password and adjust some security settings. First, run this command:

mysql_secure_installation

By default root password is empty so just press enter and continue. You will be asked if you want to change the root password, so enter "y" and enter the new password. All subsequent questions should be answered with the letter “y”.

Now you can access your root user with new password:

mariadb -u root -p

Additional configurations

Create a database

To create a new database, run this command (you can use any name instead of 'my_database'):
CREATE DATABASE my_database;

Create a user

To create a new MariaDB user, run the following command (change the 'username' and 'password' to the actual credentials):

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

Then flush privileges and exit:

FLUSH PRIVILEGES;

EXIT;

Create table

Before creating a table, select the database in which you want to do it:

USE my_database;

You can then create a table and specify what data you want to store in it (this is just an example):

CREATE TABLE employees (id INT, name VARCHAR(20), surname VARCHAR(20));

You can check your table by running this command:

SHOW TABLES;

You should see such output:

To insert some data, run this command:

INSERT INTO employees (id,name,surname) VALUES(01,"John","Smith");

To check inserted data run this command:

SELECT * FROM employees;

You should see this output:

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch