In this tutorial, I’ll show you how you can install MariaDB database server on Debian Linux system. MariaDB is a relational database management system forked from MySQL. MariaDB is fully open source and is released under the General Public License version 2.
There is no additional repository need for the installation of MariaDB database server on Debian Linux system. You just need to update system APT repositories and you’re set to go. However, to get the latest release of MariaDB packages, you’ll need to use official MariaDB upstream APT repositories.
For Galera Cluster, use the guide on Setup MariaDB Galera Cluster on Debian
Step 1: Update System
Run the following commands in your terminal to update system packages and repository content on your server.
sudo apt update && sudo apt -y upgrade
If a reboot is required after running packages update, then perform the action.
[ -e /var/run/reboot-required ] && sudo reboot
Step 2: Install MariaDB Database server
Next is to install MariaDB database server on Debian Linux system.
### Install latest from MariaDB APT repository (Recommended) ###
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s --
sudo apt update
sudo apt install mariadb-server mariadb-client
### Install default OS MariaDB package (Old) ###
sudo apt install mariadb-server mariadb-client
When prompted to set the root password, provide the password and confirm.
Installed version can be checked with the commands below.
$ apt policy mariadb-server
mariadb-server:
Installed: 1:11.2.2+maria~deb12
Candidate: 1:11.2.2+maria~deb12
Version table:
*** 1:11.2.2+maria~deb12 1000
1000 https://dlm.mariadb.com/repo/mariadb-server/11.2/repo/debian bookworm/main amd64 Packages
100 /var/lib/dpkg/status
1:11.2.1+maria~deb12 1000
1000 https://dlm.mariadb.com/repo/mariadb-server/11.2/repo/debian bookworm/main amd64 Packages
1:10.11.4-1~deb12u1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
500 http://mirror.hetzner.com/debian/packages bookworm/main amd64 Packages
...
The service name for MariaDB Database server is mysql
or mariadb
.
$ systemctl status mariadb
● mariadb.service - MariaDB 11.2.2 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Thu 2023-11-23 00:08:36 UTC; 22s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 3047 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 3048 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3050 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POS>
Process: 3091 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3093 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 3079 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 4531)
Memory: 208.7M
CPU: 777ms
CGroup: /system.slice/mariadb.service
└─3079 /usr/sbin/mariadbd
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] Plugin 'FEEDBACK' is disabled.
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] Plugin 'wsrep-provider' is disabled.
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] InnoDB: Buffer pool(s) load completed at 231123 0:08:36
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] Server socket created on IP: '127.0.0.1'.
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
Nov 23 00:08:36 deb12 mariadbd[3079]: 2023-11-23 0:08:36 0 [Note] /usr/sbin/mariadbd: ready for connections.
Nov 23 00:08:36 deb12 mariadbd[3079]: Version: '11.2.2-MariaDB-1:11.2.2+maria~deb12' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
Nov 23 00:08:36 deb12 systemd[1]: Started mariadb.service - MariaDB 11.2.2 database server.
Nov 23 00:08:36 deb12 /etc/mysql/debian-start[3095]: Upgrading MySQL tables if necessary.
Nov 23 00:08:36 deb12 /etc/mysql/debian-start[3106]: Checking for insecure root accounts.
Step 3: Secure MariaDB Database Server
The last step is securing the database server. This includes:
- Setting strong root password
- Removing anonymous users
- Disabling remote login for root user.
- Removing test database and access to it
Run the command below to secure your database server.
$ sudo mariadb-secure-installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
… Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
Dropping test database…
… Success!
Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Update authentication plugin to allow root password authentication as normal user.
$ sudo mysql -u root
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root';
FLUSH PRIVILEGES;
QUIT;
Test MariaDB database installation.
$ mysql -u root -p||mariadb -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 67
Server version: 11.2.2-MariaDB-1:11.2.2+maria~deb12 mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Confirm version from MySQL CLI:
MariaDB [(none)]> SELECT VERSION();
+-------------------------------------+
| VERSION() |
+-------------------------------------+
| 11.2.2-MariaDB-1:11.2.2+maria~deb12 |
+-------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> QUIT
That’s all. Enjoy running the MariaDB Database server on Debian Linux system.
Similar articles are:
- How to Install phpMyAdmin with Apache on Debian
- How to Install MariaDB on FreeBSD
- How to Install MariaDB on Debian 9 / Debian 8
- Install MariaDB on Ubuntu 18.04 and CentOS 7
- How to Install MariaDB on RHEL / CentOS 8