Install MariaDB 10.11 on Ubuntu 20.04 | Powerful Database Engine

Posted on

Install MariaDB 10.11 on Ubuntu 20.04 | Powerful Database Engine

In this guide, we aim to walk you through the process of installing the latest long-term support (LTS) release of MariaDB 10.11, which boasts a five-year maintenance window, on Ubuntu 20.04. MariaDB, as you likely know, is a highly regarded open-source database management system, closely related to MySQL but incorporating numerous enhanced features and performance improvements. Follow the steps below to successfully install MariaDB 10.11 on Ubuntu 20.04 Focal Fossa. This guide is proudly presented by Orcacore.

Full guide To Install MariaDB 10.11 on Ubuntu 20.04

Before embarking on the MariaDB LTS installation, ensure you possess access to your Ubuntu 20.04 server as a non-root user with sudo privileges. If you’re unsure how to achieve this, consult our comprehensive guide on Initial Server Setup with Ubuntu 20.04.

Once your server is properly configured, proceed with the subsequent steps to Install MariaDB 10.11 on Ubuntu 20.04.

Step 1 – Install Required Packages For MariaDB LTS on Ubuntu 20.04

Begin by installing the necessary packages and dependencies on your server using the following command:

sudo apt install curl software-properties-common dirmngr ca-certificates apt-transport-https -y

Upon completion, move on to the next steps, which involve adding the MariaDB 10.11 GPG key and repository to your system.

Step 2 – Add MariaDB 10.11 GPG Key on Ubuntu 20.04

To Install MariaDB 10.11 on Ubuntu 20.04, import the MariaDB 10.11 GPG key and repository using the following curl command:

# sudo mkdir -p /etc/apt/keyrings
# sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'

Step 3 – Add MariaDB 10.11 Repository on Ubuntu 20.04

Next, create a repository file for MariaDB:

sudo vi /etc/apt/sources.list.d/mariadb.sources

Add the following content to the file. This configuration tells your system where to find the MariaDB 10.11 packages.

# MariaDB 10.11 repository list - created 2023-07-02 07:16 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/10.11/ubuntu
URIs: https://mariadb.mirror.wearetriple.com/repo/10.11/ubuntu
Suites: focal
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp

Save and close the file after adding the content.

Step 4 – MariaDB 10.11 Installation on Ubuntu 20.04

Now, update the system’s package list to recognize the newly added repository, and then install MariaDB 10.11:

# sudo apt update
# sudo apt install mariadb-server mariadb-client -y

Verify the installation by checking the MariaDB version:

mariadb --version
**Output**
mariadb  Ver 15.1 Distrib 10.11.4-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Step 5 – How To Check MariaDB Status?

MariaDB should start automatically. To confirm it’s running, use the following command:

sudo systemctl status mariadb
**Output**
● mariadb.service - MariaDB 10.11.4 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: **active** (**running**) since Sun 2023-07-02 09:29:38 CEST; 53s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 2754 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 4620)
     Memory: 79.5M
     CGroup: /system.slice/mariadb.service
             └─2754 /usr/sbin/mariadbd
...

Enable MariaDB to start automatically on boot:

sudo systemctl enable mariadb

Step 6 – Run MariaDB Secure Installation Script on Ubuntu 20.04

Secure your MariaDB 10.11 installation by running the security script:

sudo mysql_secure_installation

The script will prompt you to set a root password and answer several security-related questions.

Secure MariaDB Ubuntu 20.04

Step 7 – How To Access MariaDB Shell?

Access the MariaDB shell using the following command:

sudo mysql -u root -p

Enter the root password you set earlier.

**Output**
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 39
Server version: 10.11.4-MariaDB-1:10.11.4+maria~ubu2004 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

**MariaDB [(none)]>**

Step 8 – Configure A Password-authenticated Administrative User on MariaDB

Create a new user account with password authentication:

**MariaDB [(none)]>** CREATE USER 'adminuser'@'localhost' IDENTIFIED BY 'secretpassword';

Grant all privileges to the new admin user:

**MariaDB [(none)]>** GRANT ALL PRIVILEGES ON *.* TO 'adminuser'@'localhost';

Apply the changes and exit the MariaDB shell:

**MariaDB [(none)]>** FLUSH PRIVILEGES;
**MariaDB [(none)]>** EXIT;

Step 9 – Test MariaDB Admin User

Log in with the new admin user:

sudo mariadb -u adminuser -p

Enter the admin user password.

**Output**
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 41
Server version: 10.11.4-MariaDB-1:10.11.4+maria~ubu2004 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
**MariaDB [(none)]>**

Check existing databases:

**MariaDB [(none)]>** SHOW DATABASES;
**Output**
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.005 sec)

Create a new database:

**MariaDB [(none)]>** CREATE DATABASE testdb;

Apply changes:

**MariaDB [(none)]>** FLUSH PRIVILEGES;

List existing users:

**MariaDB [(none)]>** SELECT host, user FROM mysql.user;
**Output**
+-----------+-------------+
| Host      | User        |
+-----------+-------------+
| localhost | adminuser   |
| localhost | mariadb.sys |
| localhost | mysql       |
| localhost | root        |
+-----------+-------------+
4 rows in set (0.005 sec)

Exit the MariaDB shell:

**MariaDB [(none)]>** EXIT;

Step 10 – Uninstall MariaDB from Ubuntu 20.04

To completely remove MariaDB:

sudo apt autoremove mariadb-server mariadb-client --purge -y

Remove the repository:

# sudo rm /etc/apt/sources.list.d/mariadb.sources
# sudo apt update

For more detailed information, consult the MariaDB Documentation Page.

Conclusion

You have now successfully learned to Install MariaDB 10.11 on Ubuntu 20.04. You also have acquired the knowledge on how to access the MariaDB shell, configure a password-authenticated administrative user, and perform basic tasks.

We hope you found this guide helpful. Here are some other articles you may find interesting:

Upgrade Linux Kernel to the Latest on Ubuntu 20.04

Set up OpenJDK 17 on Ubuntu 20.04

Install OpenSSL 3 on Ubuntu 20.04

Alternative Solutions to Installing MariaDB 10.11 on Ubuntu 20.04

While the above method utilizes the official MariaDB repositories for installation, alternative approaches exist that can be more suitable in specific situations. Here are two different ways to install MariaDB 10.11 on Ubuntu 20.04:

1. Using Docker

Docker provides a containerized environment, allowing you to run MariaDB without directly installing it on your host system. This can be beneficial for isolating MariaDB from other applications and managing dependencies more efficiently.

Explanation:

Docker containers package an application along with all its dependencies into a standardized unit for software development. By using a Docker image for MariaDB, you ensure a consistent environment regardless of the underlying operating system. This approach is especially useful for development and testing, as it allows you to quickly spin up and tear down MariaDB instances.

Steps:

  1. Install Docker: If Docker is not already installed, follow the instructions on the official Docker website to install it on your Ubuntu 20.04 system.

    sudo apt update
    sudo apt install docker.io -y
    sudo systemctl start docker
    sudo systemctl enable docker
  2. Pull the MariaDB 10.11 Docker Image: Pull the official MariaDB 10.11 image from Docker Hub.

    sudo docker pull mariadb:10.11
  3. Run the MariaDB Container: Create and run the MariaDB container, mapping the container’s port to a port on your host machine and setting environment variables for the root password.

    sudo docker run -d --name mariadb1011 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=your_root_password mariadb:10.11
    • -d: Runs the container in detached mode (background).
    • --name mariadb1011: Assigns a name to the container.
    • -p 3306:3306: Maps port 3306 on the host to port 3306 in the container.
    • -e MYSQL_ROOT_PASSWORD=your_root_password: Sets the root password for the MariaDB instance. Replace your_root_password with a strong password.
  4. Access the MariaDB Instance: You can now connect to the MariaDB instance running in the Docker container using any MySQL client on your host machine, connecting to localhost on port 3306.

    mysql -u root -p -h 127.0.0.1 -P 3306

2. Compiling from Source

Another method involves downloading the source code of MariaDB 10.11 and compiling it directly on your Ubuntu 20.04 system.

Explanation:

Compiling from source provides the most control over the installation process and allows you to customize MariaDB to your specific needs. However, it is a more complex process that requires installing build dependencies and configuring the build process.

Steps (Simplified):

  1. Install Build Dependencies: Before compiling, ensure you have the necessary build tools and libraries.

    sudo apt update
    sudo apt install build-essential cmake libaio-dev libncurses-dev bison -y
  2. Download the MariaDB 10.11 Source Code: Download the source code from the MariaDB website or a mirror.

    wget https://mirrors.xtom.com/mariadb/mariadb-10.11.4/source/mariadb-10.11.4.tar.gz
    tar -xzvf mariadb-10.11.4.tar.gz
    cd mariadb-10.11.4
  3. Configure and Build MariaDB: Use CMake to configure the build process, then compile and install MariaDB.

    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb
    make
    sudo make install
  4. Configure Environment: Add MariaDB binaries to your PATH and configure the necessary environment variables. You will need to manually create the my.cnf file and configure the MariaDB service. This is a complex step and beyond the scope of this brief alternative solution.

Note: Compiling from source requires a deeper understanding of the build process and system administration. The steps outlined above are a simplified overview. Refer to the official MariaDB documentation for detailed instructions and troubleshooting. This method is generally recommended for advanced users who require specific customizations.