This post shows students and new users the steps to install MySQL or MariaDB on Ubuntu Linux. MariaDB and MySQL are twins. Both MySQL and MariaDB are multithreaded, open source relational database management systems. MariaDB is a backward compatible replacement for MySQL.

You can uninstall MySQL and install MariaDB, and your applications may not even know the difference. Since these two databases are identical, we are going to write a single post detailing how to install both on Ubuntu Linux.

MariaDB maintained and developed by the MariaDB Foundation while MySQL is owned by Oracle.

If you are a student or a new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.

To start installing MariaDB and MySQL databases on Ubuntu Linux, follow the steps below.

How to install MariaDB on Ubuntu Linux

As mentioned above, MariaDB is compatible with MySQL. It is maintained and developed by the MariaDB Foundation.

MariaDB packages are available in the Ubuntu repositories. So it can simply be installed using the suitable package management.

To install MariaDB, run the following commands.

sudo apt update
sudo apt install mariadb-server

After installation, you can run the following commands to view the status of the MariaDB service.

sudo systemctl status mariadb

After running the above command, it should generate lines similar to the ones shown below.

mariadb.service - MariaDB 10.3.31 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-09-15 16:40:20 CDT; 22s ago
       Docs: man:mysqld(8)
   Main PID: 3007 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 4651)
     Memory: 65.6M
     CGroup: /system.slice/mariadb.service
             └─3007 /usr/sbin/mysqld

Sep 15 16:40:20 ubuntu2004 /etc/mysql/debian-start[3045]: mysql
Sep 15 16:40:20 ubuntu2004 /etc/mysql/debian-start[3045]: performance_schema

To check which versions of MariaDB are running, run the following commands.

mysql -V

That should generate lines similar to the following.

How to install the latest versions and update MariaDB

The versions available in the Ubuntu repositories for MariaDB are not the most recent. For the latter, you’ll want to add MariaDB repositories to Ubuntu. The repositories are maintained at the following link.

MariaDB – MariaDB Repository Configuration – MariaDB

There, select the version of Ubuntu you are installing for, then select the latest version of MariaDB. At the time of writing, the latest version of MariaDB is 10.6.

Run the commands to add the 10.6 version to Ubuntu 20.04.

sudo apt-key adv --fetch-keys ''
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] focal main'

Then install MariaDB

sudo apt update
sudo apt install mariadb-server

How to install MySQL on Ubuntu Linux

MySQL is also available through Ubuntu’s default repositories. Therefore, one can simply run the following commands to install MySQL using the apt package management tool.

sudo apt update
sudo apt install mysql-server

After installing MySQL, you can check the status of your service by running the following commands.

sudo systemctl status mysql

That should generate lines similar to the following.

How to install the latest version of MySQL on Ubuntu Linux

Although the MySQL server packages are included with Ubuntu, they may not necessarily be the latest. If you want to always get the latest versions of the MySQL server downloaded to their servers, you may want to add their repository.

The link below takes you to the repository file.

Visit the download page and search Ubuntu / Debian (architecture independent), DEB package. Click the Download button to get the package from the repository …

You can run the following commands, updating the version number (0.8.15-1) at the time of writing, with the latest information from the above file.

cd /tmp
sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

When you run the above commands, you should get a configuration message

Just select okay as shown in the picture below.

Now that the repository is installed, run the following commands to install

sudo apt update
sudo apt upgrade

How to protect MariaDB and MySQL

Both MariaDB and MySQL come with a script that allows you to perform some security operations.

Run the following commands to invoke the script and perform some recommended tasks to protect the database.

sudo mysql_secure_installation

Both MariaDB and MySQL servers come with the root user configured to use the auth_socket default authentication method.

the auth_socket The plugin authenticates users connecting from the local host through the Unix socket file. This means that you cannot authenticate as root by providing a password.

To log in to the MariaDB and MySQL servers as root, just run the following command. You don’t need a password as it uses the auth_socket method.

sudo mysql

You should do that!


In this tutorial we have seen how to install MariaDB or MySQL on Ubuntu Linux. If you find any errors above or have something to add, use the comment form below.

Write A Comment