In this guide, we want to teach you to Install The latest long-term release MariaDB 10.11, which is maintained for five years, on Ubuntu 20.04. As you know MariaDB is an open-source and popular database similar to MySQL, but it has more features and improvements.
To install MariaDB LTS on Ubuntu 20.04 Focal, you can follow the steps below.
How To Install MariaDB 10.11 on Ubuntu 20.04?
Before you start your MariaDB LTS installation, you must have access to your server as a non-root user with sudo privileges. To do this, you can check this guide on Initial Server Setup with Ubuntu 20.04.
Then, follow the steps below to complete this guide.
Step 1 – Install Required Packages For MariaDB LTS on Ubuntu 20.04
First, you need to install the required packages and dependencies on your server with the following command:
sudo apt install curl software-properties-common dirmngr ca-certificates apt-transport-https -y
When you are done, proceed to the next steps to add MariaDB 10.11 GPG key and Repository.
Step 2 – Add MariaDB 10.11 GPG Key on Ubuntu 20.04
At this point, you need to import the MariaDB 10.11 GPG key and Repository by 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
Now you need to create a repo file for MariaDB by using the following command:
sudo vi /etc/apt/sources.list.d/mariadb.sources
Add the following content to the file:
# 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
When you are done, save and close the file.
Step 4 – MariaDB 10.11 Installation on Ubuntu 20.04
Now you can run the system update to apply the newly added repository and install MariaDB LTS on your server:
# sudo apt update
# sudo apt install mariadb-server mariadb-client -y
Verify your MariaDB installation by checking its 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 will start automatically on your server. To check that it is active and running on your server, run 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
...
Also, you can enable your MariaDB service to start on boot:
sudo systemctl enable mariadb
Step 6 – Run MariaDB Secure Installation Script on Ubuntu 20.04
At this point, you can secure your MariaDB 10.11 installation on Ubuntu 20.04 by running a security script.
To do this, use the following command:
sudo mysql_secure_installation
You will be asked to set a root password for your MariaDB and from there enter yes to answer other questions.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Step 7 – How To Access MariaDB Shell?
At this point, you can access your MariaDB shell on Ubuntu 20.04 with the command below:
sudo mysql -u root -p
Enter your root password and press enter.
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
At this point, you can create a new user account in the database server with password authentication. From your MariaDB shell, create an admin user with a secret password by using the command below:
MariaDB [(none)]> CREATE USER 'adminuser'@'localhost' IDENTIFIED BY 'secretpassword';
Next, grant all privileges to your admin user with the command below:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'adminuser'@'localhost';
To apply the changes, flush the privileges with the following command and exit from your MariaDB shell:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Step 9 – Test MariaDB Admin User
At this point, you can log in to your MariaDB with the admin user you have just created by using the following command on Ubuntu 20.04:
sudo mariadb -u adminuser -p
Enter your Admin user password and press enter:
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)]>
To check the existing databases, you can run the command below::
MariaDB [(none)]> SHOW DATABASES;
Output
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.005 sec)
To create a new database, you can use the following command:
MariaDB [(none)]> CREATE DATABASE testdb;
Now apply all the changes by flushing the privileges:
MariaDB [(none)]> FLUSH PRIVILEGES;
You can list all the existing users in your database engine with the following command:
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)
Then, you can exit from your MariaDB shell by using the command below:
MariaDB [(none)]> EXIT;
Step 10 – Uninstall MariaDB from Ubuntu 20.04
If you no longer wish to use MariaDB and want to remove it in full, execute the following command:
sudo apt autoremove mariadb-server mariadb-client --purge -y
Note, this will remove MariaDB completely including all database data.
To remove the repository, use the following command.
# sudo rm /etc/apt/sources.list.d/mariadb.sources
# sudo apt update
For more information, you can visit the MariaDB Documentation Page.
Conclusion
At this point, you have learned to Install The latest long-term release MariaDB 10.11, which is maintained for five years, on Ubuntu 20.04. Also, you have learned to access your MariaDB shell Configure A Password-authenticated Administrative User, and do basic tasks.
Hope you enjoy it. You may be interested in these articles:
Upgrade Linux Kernel to the Latest on Ubuntu 20.04