Hostomy Blog

How to install MariaDB 10.6 on Ubuntu 20.04 server

Feb 14, 2022

By Rahul Mukati

How to install MariaDB 10.6 on Ubuntu 20.04 server

In this tutorial, we'll cover how to install MariaDB 10.6 on an Ubuntu 20.04 server.

Step 1 - Login to your server

Login to your server with the root user.

ssh [email protected]

Step 2 - Update your server

After a successful login, we need to update our server. For this we run the following command:

sudo apt-get update && sudo apt-get upgrade -y

Step 3 - Install required packages

Next, we will install software-properties-common. Run the below command for that.

sudo apt install software-properties-common -y

Step 4 - Add MariaDB APT Repository

Now with the below commands, we are going to add MariaDB signing key and add MariaDB APT repository.

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.6

You’ll get an output with contents like the ones shown below:

[info] Checking for script prerequisites.
[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

Step 5 - Install MariaDB 10.6

Now, we will make MariaDB 10.6 installation by running the below command:

sudo apt update
sudo apt install mariadb-server

Step 6 - Secure MariaDB installation

Once MariaDB is installed, run the below MySQL script to secure MariaDB.

sudo mariadb-secure-installation

You will be asked for some options [Y/n], you can take a look below for that.

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] Y
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
 ... 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!

Step 7 - Testing MariaDB

Now we are all set, MariaDB is installed and now we can test its status by running the below command.

sudo systemctl status mariadb

You'll receive output that is similar to the following:

● mariadb.service - MariaDB 10.6.4 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2021-10-19 11:37:25 UTC; 9s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 3023 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 14 (limit: 4703)
   CGroup: /system.slice/mariadb.service
           └─3023 /usr/sbin/mariadbd

If MariaDB isn’t running, you can start it with the command:

sudo systemctl start mariadb

Step 8 - Enable MariaDB to start on server reboot

Run the below command to enable MariaDB to automatically start when the server is rebooted.

sudo systemctl enable mariadb

Bingo! We're done with the installation and your MariaDB 10.6 is ready for use!