Install MariaDB Server on Ubuntu 22.04|20.04
MariaDB is the most powerful and widely used relational database management system developed by the MariaDB Foundation. We have many articles on the installation of MariaDB on various Linux distributions. This guide will focus on the installation of MariaDB on Ubuntu 22.04|20.04 Linux system.
For those new to MariaDB, it is a community-developed fork of MySQL database system. It was primarily designed to be free and open source, without any compromise in speed, stability and scalability. Most Linux distributions will have MariaDB in their upstream repositories available for quick installation with the default OS package manager.
#1) Install MariaDB Server on Ubuntu 22.04|20.04
We always start our installations by ensuring the system is updated. This can be achieved by running the commands:
sudo apt update
sudo apt -y upgrade
Once the system is updated, use the following commands to install MariaDB Server on Ubuntu22.04|20.04.
sudo apt install software-properties-common mariadb-server mariadb-client
Confirm that the service is started.
$ systemctl status mariadb
● mariadb.service - MariaDB 10.5.12 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-11-08 23:50:42 EAT; 2h 46min ago
Main PID: 56606 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 9482)
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] Plugin 'FEEDBACK' is disabled.
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] InnoDB: Buffer pool(s) load completed at 211108 23:50:42
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] Server socket created on IP: '127.0.0.1'.
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] Reading of all Master_info entries succeeded
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] Added new Master_info '' to hash table
Nov 08 23:50:42 ubuntu22 mariadbd: 2021-11-08 23:50:42 0 [Note] /usr/sbin/mariadbd: ready for connections.
Nov 08 23:50:42 ubuntu22 mariadbd: Version: '10.5.12-MariaDB-1build1' socket: '/run/mysqld/mysqld.sock' port: 3306 Ubuntu 21.10
Nov 08 23:50:42 ubuntu22 systemd: Started MariaDB 10.5.12 database server.
Nov 08 23:50:43 ubuntu22 /etc/mysql/debian-start: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables
By default, you should be able to access the mysql command line as root user without being prompted to provide a password. Let’s ensure we harden our MariaDB server and set the root password.
$ sudo mysql_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
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
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
Remove anonymous users? [Y/n] y
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
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...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
#2) Confirm MariaDB Server Installation on Ubuntu 22.04/20.04
Let’s confirm our installation of MariaDB server on Ubuntu22.04/20.04:
$ mysql -V
mysql Ver 15.1 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Create a test database.
$ sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> DROP DATABASE testdb;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> QUIT
Enjoy using MariaDB database server on Ubuntu22.04|20.04 Linux system.