Install MariaDB 10.7 on Ubuntu 18.04

In this tutorial you are going to learn how to install MariaDB 10.7 on Ubuntu 18.04. MariaDB is a derivative of MySQL. In other words, it’s a superior, drop-in replacement for MySQL. A drop-in replacement means you may use the analog MariaDB server to replace the conventional MySQL server and gain access to all of MariaDB’s features without having to change your application code.

MariaDB is a dependable, scalable, and quick database. In comparison to MySQL, it has a bigger number of storage engines. MariaDB also comes with a number of plugins and utilities that allow it to be used in a variety of situations.

How to Install MariaDB 10.7 on Ubuntu 18.04

  • Lets begin with updating and upgrading the system by running the command below.
sudo apt update && sudo apt upgrade -y
  • After updating and upgrading your system, run the following command to reboot.
sudo systemctl reboot
  • Then Install dependency packages
sudo apt install curl apt-transport-https software-properties-common lsb-release ca-certificates gnupg2

Sample output

Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20210119~20.04.2).
ca-certificates set to manually installed.
curl is already the newest version (7.68.0-1ubuntu2.7).
software-properties-common is already the newest version (0.99.9.8).
The following packages were automatically installed and are no longer required:
  libfprint-2-tod1 libllvm9
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  apt-transport-https gnupg2
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,264 B of archives.
After this operation, 213 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.6 [4,680 B]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 gnupg2 all 2.2.19-3ubuntu2.1 [4,584 B]
Fetched 9,264 B in 1s (10.2 kB/s)

Add MariaDB APT Repository on Ubuntu 18.04

  • To add MariaDB APT repository, run the command below.
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.7

Sample output

# [info] Checking for script prerequisites.
# [info] MariaDB Server version 10.7 is valid
# [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
# [info] Adding trusted package signing keys...
# [info] Running apt-get update...
# [info] Done adding trusted package signing keys
  • Update your packages to latest
sudo apt update

Install MariaDB 10.7 on Ubuntu 18.04

  • Install the MariaDB package now that the repository has been added.
sudo apt install mariadb-server

Sample output

 Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfprint-2-tod1 libllvm9
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  galera-4 gawk libaio1 libconfig-inifiles-perl
  libdbd-mariadb-perl libhtml-template-perl libmariadb3
  libpmem1 libreadline5 libterm-readkey-perl
  mariadb-client-10.7 mariadb-client-core-10.7
  mariadb-common mariadb-server-10.7
  mariadb-server-core-10.7 socat
Suggested packages:
  gawk-doc libipc-sharedcache-perl mailx mariadb-test
The following NEW packages will be installed:
  galera-4 gawk libaio1 libconfig-inifiles-perl
  libdbd-mariadb-perl libhtml-template-perl libmariadb3
  libpmem1 libreadline5 libterm-readkey-perl
  mariadb-client-10.7 mariadb-client-core-10.7
  mariadb-common mariadb-server mariadb-server-10.7
  mariadb-server-core-10.7 socat
0 upgraded, 17 newly installed, 0 to remove and 1 not upgraded.
Need to get 27.8 MB of archives.
After this operation, 224 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 gawk amd64 1:5.0.1+dfsg-1 [418 kB]
Get:2 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/ubuntu focal/main amd64 mariadb-common all 1:10.7.3+maria~focal [4,044 B]
  • MariaDB service should start automatically, check if it’s running using the command below.
sudo systemctl status mariadb

Sample output

● mariadb.service - MariaDB 10.7.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service;>
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Sat 2022-02-19 11:29:>
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 19987 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 15 (limit: 4588)
     Memory: 58.3M
     CGroup: /system.slice/mariadb.service
             └─19987 /usr/sbin/mariadbd

Feb 19 11:29:38 ubuntu mariadbd[19987]: 2022-02-19 11:29:>
Feb 19 11:29:38 ubuntu mariadbd[19987]: Version: '10.7.3->
Feb 19 11:29:38 ubuntu systemd[1]: Started MariaDB 10.7.3>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20005]: Up>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20008]: Lo>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20008]: Lo>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20008]: Th>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20008]: Th>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20008]: Yo>
Feb 19 11:29:38 ubuntu /etc/mysql/debian-start[20016]: Ch>
lines 1-24/24 (END)
  • Check MariaDB version installed.
mysql -V

Sample output

mysql  Ver 15.1 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Secure MariaDB 10.7 installation on Ubuntu 18.04

  • To secure your MariaDB 10.7 on Ubuntu 18.04 run the following command.
sudo mysql_secure_installation

Sample output

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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!
  • After you’ve completed the process of securing MariaDB, you can access MariaDB shell as root user by providing password that you have previously set above.
sudo mysql -u root -p

Sample output when you enter the password.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 45
Server version: 10.7.3-MariaDB-1:10.7.3+maria~focal 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)]> 

Uninstall MariaDB 10.7 on Ubuntu 18.04

  • To completely remove MariaDB, run the command below.
sudo apt purge mariadb-server

Then

sudo rm -rf /var/lib/mysql/
  • You have reached the end of the article, Congratulations. You have learned how to Install MariaDB 10.7 on Ubuntu 18.04.

Other Tutorial

Install WordPress with LEMP Stack on Ubuntu 22.04

Install WordPress with LAMP Stack on Ubuntu 22.04

Install and Configure VNC server on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment