Page cover image

Install MariaDB on Linux

Learn how to install mariadb service on different linux distributions

This documentation has been extracted from mariadb oficial page

This guide will walk you through the steps to install MariaDB 11.4.3 on a Linux system based on Debian (such as Ubuntu, Debian itself, or other derivatives). MariaDB is an open-source relational database system that is a popular choice for many web applications.


Prerequisites

  • A running Debian-based system (e.g., Ubuntu 22.04, Debian 11).

  • Root or sudo access.

  • A stable internet connection for package downloads.

Step-by-Step Installation Guide

1. Update Your System

First, make sure your package lists are up to date.

sudo apt update
sudo apt upgrade -y

2. Install Prerequisites

MariaDB requires some dependencies to be installed on your system, like software-properties-common to manage repositories.

sudo apt install software-properties-common dirmngr -y

3. Add the MariaDB 11.4 Repository

To install the latest version of MariaDB (11.4.3), you need to add the official MariaDB repository to your system.

  1. Import the MariaDB GPG key:

    sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
  2. Add the MariaDB repository:

    sudo add-apt-repository 'deb [arch=amd64] https://mirror.mariadb.org/repo/11.4/debian bullseye main'

    If you're using a different Debian-based distribution, replace bullseye with your version codename (e.g., focal for Ubuntu 20.04).

4. Update Package Lists Again

After adding the MariaDB repository, update your package list to include the new packages from MariaDB:

sudo apt update

5. Install MariaDB 11.4.3

Now you can install MariaDB 11.4.3 using the following command:

sudo apt install mariadb-server mariadb-client -y

6. Start and Enable MariaDB Service

After installation, start the MariaDB service and enable it to automatically start on system boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

7. Secure the MariaDB Installation

MariaDB includes a security script to remove default settings that are insecure. Run this script:

sudo mysql_secure_installation

You will be prompted to:

  • Set a root password (if not set during installation).

  • Remove anonymous users.

  • Disallow remote root login.

  • Remove the test database.

  • Reload privilege tables.

Answer "Y" to all prompts for a secure installation.

8. Verify Installation

To verify that MariaDB is correctly installed and running, use:

sudo systemctl status mariadb

You should see the service status as "active" (running).

Additionally, log into the MariaDB shell:

sudo mariadb -u root -p

Enter the root password you created earlier, and you'll be logged into the MariaDB shell. To confirm the version, run:

SELECT VERSION();

You should see something like:

+----------------+
| VERSION()      |
+----------------+
| 11.4.3-MariaDB |
+----------------+

9. Basic Configuration (Optional)

You can configure MariaDB by editing the my.cnf configuration file:

sudo nano /etc/mysql/my.cnf

Make any changes you need, then restart the service:

sudo systemctl restart mariadb

Common Commands

  • Start MariaDB:

    sudo systemctl start mariadb
  • Stop MariaDB:

    sudo systemctl stop mariadb
  • Restart MariaDB:

    sudo systemctl restart mariadb
  • Check MariaDB Status:

    sudo systemctl status mariadb

Last updated

Was this helpful?