
How to Install MariaDB 10.7 on Ubuntu 20.04: A Step-by-Step Guide
Upgrading your database server is a critical step for enhancing performance, security, and gaining access to modern features. While Ubuntu 20.04’s default repositories provide a version of MariaDB, it’s often not the latest. Installing a specific, newer version like MariaDB 10.7 requires adding the official MariaDB repository.
This comprehensive guide will walk you through the entire process of installing MariaDB 10.7 on your Ubuntu 20.04 server, ensuring a stable and secure setup.
Prerequisites
Before you begin, ensure you have the following:
- An Ubuntu 20.04 server.
- A user account with
sudo
privileges. - Access to the command line/terminal.
Step 1: Update Your System and Install Dependencies
First, it’s always best practice to update your system’s package index and install a few essential packages that are required to add and manage custom repositories.
Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade
sudo apt install software-properties-common dirmngr apt-transport-https -y
These packages will allow you to securely add and manage the GPG key and the repository source for MariaDB.
Step 2: Import the MariaDB GPG Key and Add the Repository
To ensure the packages you download are authentic, you must first import the official MariaDB GPG key. This key is used to sign the software, verifying that it has not been tampered with.
Execute this command to import the key:
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Once the key is successfully imported, you need to add the MariaDB 10.7 repository to your system’s sources list. This tells your package manager where to find the correct version of MariaDB.
Create and add the repository configuration with this single command:
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirror.realcompute.io/mariadb/repo/10.7/ubuntu focal main'
After adding the new repository, you must update your package index again to include the package lists from the newly added source.
sudo apt update
Step 3: Install MariaDB 10.7 Server and Client
With the repository configured, you are now ready to install the MariaDB server and client packages.
Run the installation command:
sudo apt install mariadb-server mariadb-client -y
The package manager will now fetch and install MariaDB 10.7 and all of its required dependencies.
Step 4: Verify the Installation
After the installation process is complete, the MariaDB service should start automatically. You can verify its status to ensure it’s running correctly.
sudo systemctl status mariadb
You should see an output indicating the service is active (running)
.
To confirm you have installed the correct version, you can run:
mysql -V
The output should display version 10.7, confirming a successful installation. For example: mysql from 10.7.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using readline 5.2
Step 5: Secure Your MariaDB Installation
A fresh installation of MariaDB comes with default settings that are not secure for a production environment. MariaDB includes a security script to help you easily lock down your database server.
This is a critical, non-optional step for any server.
Run the interactive security script:
sudo mysql_secure_installation
The script will guide you through several essential security questions. Here are the recommended answers:
- Enter current password for root (enter for none): Press Enter as no password is set by default.
- Switch to unix_socket authentication? [Y/n]: Press Y. This is a more secure authentication method for the root user.
- Change the root password? [Y/n]: Press Y and set a strong, unique password for the database root user.
- Remove anonymous users? [Y/n]: Press Y. Anonymous users are a security risk and should be removed.
- Disallow root login remotely? [Y/n]: Press Y. Disabling remote root login is a fundamental security best practice.
- Remove test database and access to it? [Y/n]: Press Y. The test database is not needed for a production environment.
- Reload privilege tables now? [Y/n]: Press Y to apply all your changes immediately.
Your MariaDB installation is now significantly more secure.
Managing the MariaDB Service
Now that MariaDB is installed, you can manage it using standard systemctl
commands.
- To stop the database server:
bash
sudo systemctl stop mariadb
- To start the database server:
bash
sudo systemctl start mariadb
- To restart the server:
bash
sudo systemctl restart mariadb
- To enable MariaDB to start on boot (highly recommended):
bash
sudo systemctl enable mariadb
You have now successfully installed and secured MariaDB 10.7 on your Ubuntu 20.04 system. Your server is ready to host databases for your applications with improved performance and security features.
Source: https://kifarunix.com/install-mariadb-10-7-on-ubuntu/