How to Install MariaDB 10.x on Ubuntu 22.04 or 20.04


MariaDB is a free and open-source relational database management system (RDBMS) that is a fork of the popular MySQL database. It is designed to be a drop-in replacement for MySQL and offers many of the same features and benefits, with additional enhancements and improvements.

Benefits of using MariaDB include:

  • High performance and scalability
  • Support for advanced data types and storage engines
  • Improved security features
  • Robust community support and active development
  • Compatibility with existing MySQL applications and tools
  • Flexibility for customization and integration with other systems

Features of MariaDB include:

  • Support for SQL (Structured Query Language)
  • Support for ACID (Atomicity, Consistency, Isolation, Durability) transactions
  • Support for stored procedures, triggers, and views
  • Support for replication and clustering
  • Support for full-text search and spatial data
  • Support for data encryption and role-based access control

This tutorial will show you how to install the latest versions of MariaDB on Ubuntu 22.04 and Ubuntu 20.04 LTS using the official MariaDB.org repository. The tutorial will cover long-term releases, such as 10.5 and 10.6, as well as short-term releases, including 10.7, 10.8, and 10.9, along with the newest release, 10.10, on the Ubuntu Jammy Jellyfish and Focal Fossa releases.

Step 1: Update Ubuntu

First, update your system to ensure all existing packages are up to date.

sudo apt update

Optionally, you can list the updates for users who require review or are curious to see what is available to update. This can be good if you have a specific you forgot to place; use the apt-hold command.

sudo apt --list upgradable

Proceed to upgrade any outdated packages using the following command.

sudo apt upgrade

Step 2: Install Dependencies

The first step is to install the dependencies needed for the installation. Use the following command in your terminal.

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

Step 3: Import MariaDB Repository

Now this section will go over importing the LTS branches, which for production I would recommend, or for users that prefer using the latest versions of MariaDB on a CMS like WordPress and do not mind upgrading their versions every six months to 12 months, use the short-term release.

See also
How to Install BleachBit on Ubuntu 22.04 or 20.04

Import the GPG key to verify the MariaDB packages first with the following command.

curl -fsSL http://mirror.mariadb.org/PublicKey_v2 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg > /dev/null

Next, import the repository; the commands will work with 22.04 and 20.04 LTS releases.

Option 1: Import MariaDB 10.5 (Long-term release)

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.5/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Option 2: Import MariaDB 10.6 (Long-term release)

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.6/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Option 3: Import MariaDB 10.7 (Short-term release)

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.7/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Option 4: Import MariaDB 10.8 (Short-term release)

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.8/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Option 5: Import MariaDB 10.9 (Short term release)

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.9/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Option 6: Import MariaDB 10.10 (Short-term release) – Latest Release

echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] http://mirror.mariadb.org/repo/10.10/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Next, refresh your APT repository with the following command.

sudo apt update

Step 4: Install MariaDB

To install MariaDB, you must install the client and the server packages. This can be done as follows:

sudo apt install mariadb-server mariadb-client -y

Confirm the installation of MariaDB by checking the version and build.

mariadb --version

Example output with MariaDB 10.10 installed:

mariadb  Ver 15.1 Distrib 10.10.2-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

Step 5: Enable MariaDB Service

With the installation of MariaDB complete, you can check the status of the database software by using the following systemctl command.

systemctl status mariadb

Example:

MariaDB is usually activated by default, but if it is not, you can start it using the following command.

sudo systemctl start mariadb

Stop MariaDB:

sudo systemctl stop mariadb

Enable MariaDB on system startup:

sudo systemctl enable mariadb

Disable MariaDB on system startup:

sudo systemctl disable mariadb

Restart the MariaDB service:

sudo systemctl restart mariadb

Step 6: Run MariaDB Security Script

When installing a new version of MariaDB, it is common practice in the industry to consider the default settings weak and potentially pose a security risk. Running the installation security script during the MariaDB installation process is highly recommended to address this concern. This script will help to secure the installation and prevent potential intrusion or exploitation by malicious actors.

To start, use the following command to execute the mysql_secure_installation script.

sudo mysql_secure_installation

After executing the mysql_secure_installation script, the next step is to proceed with the settings and configure the root password, disallow remote access from external sources, remove anonymous user accounts, and delete the test database.

See also
How to Install PowerShell on Ubuntu 22.04 or 20.04

Example:

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 <---- Type Y then press the ENTER KEY.
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] Y <---- Type Y then press the ENTER KEY.
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


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 <---- Type Y then press the ENTER KEY.
 ... 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 <---- Type Y then press the ENTER KEY.
 ... 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 <---- Type Y then press the ENTER KEY.
 - 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 <---- Type Y then press the ENTER KEY.
 ... 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!

Additional Commands & Tips

Run MariaDB Database Tables Upgrade Tool

For users who have upgraded from an earlier version of MariaDB, such as from 10.5 to 10.10, it is recommended to use the following steps and run the tool designed to check and fix any issues with the version upgrade. To begin the upgrade process, or check the status of your database tables, execute the following command.

sudo mariadb-upgrade

Example output:

I would suggest running this command in any case. As you can see from the previous example, if it has already been executed, it will indicate it as such. If not, the command will display a detailed list of tables that will be checked and updated for compatibility with MariaDB.

See also
How to Install Ubuntu Cleaner on 22.04 or 20.04

Remove MariaDB

If you have decided to remove MariaDB, run the following command completely.

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

Please note that the –purge flag will delete MariaDB, including all database data. Do not use the purge flag if you wish to keep the data.

Finally, use the following command to remove the repository and GPG key.

sudo rm /etc/apt/sources.list.d/mariadb.list /usr/share/keyrings/mariadb.gpg

Conclusion

In summary, this guide has provided a step-by-step demonstration of installing the latest versions of MariaDB on Ubuntu 22.04 and 20.04 LTS. The installation process outlined the commands needed to successfully install MariaDB versions 10.10, 10.9, 10.8, 10.7, 10.6, and 10.5 using the official MariaDB.org repository. By following the guide and its detailed steps, it should be easy for users to get started with using MariaDB on their Ubuntu systems.

1 thought on “How to Install MariaDB 10.x on Ubuntu 22.04 or 20.04”

Leave a Comment

Index
Share to...