How to Easily Install MariaDB on Ubuntu 22.04

What is MariaDB?

MariaDB is a popular open-source database management system that is widely used for building and managing databases. It is a fork of MySQL and offers enhanced performance, scalability, and security features. In this tutorial, I will guide you through the step-by-step process of installing MariaDB on Ubuntu 22.04, but this should work on any DEB based distro just as easily (Debian, Xubuntu, Kubuntu, Lubuntu, etc).

Step-by-step guide to installing MariaDB on Ubuntu 22.04


Make sure you have access to a terminal and have administrative privileges (root) on your Ubuntu system.

Step 1: Update & Upgrade

The first step is to update your Ubuntu 22.04 system to ensure you are all updated. It is good practice in general to always ensure you update & upgrade your system before making any big changes. Open the terminal and run the following commands:

sudo apt update && sudo apt upgrade -y

Step 2: Install MariaDB

Now that your system is updated, you can proceed with the installation of MariaDB. Return to the terminal and run the following command:

sudo apt install mariadb-server

This command will install the MariaDB server and dependencies.

Step 3: Start and enable MariaDB

After the installation is complete, you need to start the MariaDB service and enable it to start automatically at system boot. Run the following commands:

sudo systemctl start mariadb

sudo systemctl enable mariadb

Step 4: Secure your MariaDB installation

By default, MariaDB installation is not secured. You should always run the security script provided by MariaDB after any installation of MariaDB so you can set a root password, remove anonymous users, and disable remote root login. To do this, run the following command and follow the prompts:

sudo mysql_secure_installation

Configuring MariaDB after installation

Now that MariaDB is installed and secured, you can proceed with the configuration. This step is technically optional, but I highly recommend it to ensure optimal performance and security.

Step 1: Adjusting the MariaDB configuration file

Open the MariaDB configuration file in a text editor, we’re using nano here as it is the easiest to work with (in my humble opinion) within the terminal:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

In this file, you can modify various settings such as the maximum allowed packet size, the character set, and the default storage engine. Make the necessary adjustments according to your requirements. Save the file (Press CTRL + O)  and exit the text editor (Press CTRL + X).

Step 2: Restart MariaDB

To apply the changes you made to the configuration file, you need to restart MariaDB. Run the following command:

sudo systemctl restart mariadb

Step 3: Creating a new database and user

To create a new database and user, you can use the MariaDB command-line interface. Open the terminal and run the following command:

sudo mysql -u root -p

Enter your root password when prompted. Once you are in the MariaDB shell, you can create a new database and user with the following commands:

CREATE DATABASE dbname;CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';FLUSH PRIVILEGES;

Replace dbname, username, and password with your desired values. This will create a new database, a new user, and grant all privileges to the user on the database.

If you are planning on using MariaDB a lot, or have plans to run a bunch of different webapps that require MariaDB, I highlyrecommend Adminer, rather than PhpMyAdmin. Adminer is a single .php file, so it’s super easy to install. Just drag and drop it into your web servers public folder and voila! MariaDB is ready to be used!

You can check out Adminer here.

This tutorial is part of our Docker LEMP stack tutorial, where we guide you through the process of setting up a complete web development environment using Docker, Linux, Nginx, MariaDB, and PHP. Be sure to check out the other tutorials in the series to learn more about building and deploying web applications with ease!

By Zeekz

Leave a Reply

Your email address will not be published. Required fields are marked *