Cybersecurity Updates & Tools

Install MariaDB on Ubuntu 18.04: Two Methods and Secure Setup

MariaDB is an open-source, multi-threaded relational database management system and a fully backward-compatible replacement for MySQL. It was created by some of the original MySQL developers after Oracle acquired MySQL in 2010, and it is actively maintained by the MariaDB Foundation.

MariaDB is wire-compatible with MySQL: it uses the same SQL syntax, the same mysql command-line client, and the same connection protocols. Applications configured to connect to MySQL will connect to MariaDB without any code changes.

This guide covers two ways to install MariaDB on Ubuntu 18.04: from the Ubuntu default repositories (simpler, version 10.1) and from the official MariaDB repository (newer, version 10.3).

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install MariaDB on Ubuntu: From the Ubuntu Repositories

Ubuntu 18.04 includes MariaDB 10.1 in its main repositories. This version is older than what the MariaDB project currently ships, but it is well-tested, stable, and sufficient for most applications.

Update the package index and install MariaDB:

bashsudo apt updatesudo apt install mariadb-server

MariaDB starts automatically after installation. Verify the service is running:

bashsudo systemctl status mariadb

The output should show Active: active (running) with the status message “Taking your SQL requests now.” Confirm the installed version:

bashmysql -V

The command is mysql, not mariadb. MariaDB ships the mysql binary for full backward compatibility with scripts and applications that reference MySQL tooling. The version string in the output includes “MariaDB” to identify the database engine.

Install MariaDB on Ubuntu from the Official MariaDB Repository

The official MariaDB repository provides MariaDB 10.3 for Ubuntu 18.04 Bionic. This version includes more recent features, performance improvements, and a longer upstream support window than the version bundled with Ubuntu.

Visit the MariaDB Repository Configuration Tool page before proceeding to confirm the latest available version for Ubuntu 18.04 Bionic.

Add the MariaDB GPG key:

bashsudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

The fingerprint 0xF1656F24C74CD1D8 is the official MariaDB signing key registered with the Ubuntu keyserver. Importing it tells apt to trust packages from the MariaDB repository.

Add the MariaDB 10.3 repository:

bashsudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://archive.mariadb.org/mariadb-10.3.39/repo/ubuntu/ bionic main'

If add-apt-repository is not found, install software-properties-common first.

Update and install:

bashsudo apt updatesudo apt install mariadb-server

Run mysql -V to confirm the output now reports 10.3.x-MariaDB.

Secure MariaDB and Connect from the Command Line

Run the security hardening script. A fresh MariaDB installation has several insecure defaults. The mysql_secure_installation script walks you through fixing them:

bashsudo mysql_secure_installation

The script prompts you to complete five tasks:

  • Set a root user password (disabled by default on fresh installations)
  • Remove anonymous user accounts that allow anyone to connect without a username
  • Restrict root login to localhost to prevent remote root access
  • Remove the test database that is accessible to all users by default
  • Reload privilege tables so all changes take effect immediately

Answer Y to all prompts.

Connect from the command line. Log in to MariaDB as root:

bashmysql -u root -p

Enter the root password you set during mysql_secure_installation. You will land at the MariaDB prompt (MariaDB [(none)]>). From here you can create databases, manage users, run queries, and configure replication.

Type EXIT; or press Ctrl+D to close the session.

MariaDB is now installed and secured on your Ubuntu 18.04 server. Next steps include creating application databases and dedicated users, setting up automated backups, and optionally installing phpMyAdmin if you prefer a browser-based management interface. Leave a comment below if you run into any issues.