Welcome to Something!
In this guide, you will learn how to install MariaDB to your powerful VPS
MariaDB is an alternative database engine compared to MySQL.

This guide was created for Ubuntu 18.04 but should work on another Ubuntu flavors.

Need help connecting to your VPS? Check out this tutorial!

- Summary

This tutorial aims to download MariaDB and secure it. To do that we need to execute 3 commands. If you need detailed instructions, follow the next part of this guide.

Note! Each line is a command that needs to run separately
$ sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation


- Detailed instructions

1. Installing the MariaDB server

The first step we need to do is to make sure our operating system and it's libraries is up-to-date. To do that we need to run the following command

$ sudo apt-get update

Next up we need to install MariaDB, to do that we need to run the following command:

$ sudo apt install mariadb-server
If you get any prompts asking to restart services, do not be afraid, read the instructions (different per OS) and select the option you wish to use.

Beware! Your database is not secured yet and will have no password requirements so we need to secure it.

2. Securing the MariaDB server

To secure our MariaDB database and finish the setup sequence we need to run the following command

$ sudo mysql_secure_installation

The command / script mysql_secure_installation will go through a series of questions that you can answer as you wish. As you can see it says MySQL even though our database is a MariaDB, that is because MariaDB is a fork of MySQL, hence all commands and scripts of MySQL will usually also work with MariaDB.

3. Setting up the password library for MariaDB (Optional)

By default MariaDB will use a Linux library to allow you to connect to it. This is useful if you do not have any external connections but if you wish to have multiple accounts or connect from third party applications or computers, you will need to use the mysql_native_password password authentication method.

To do that, you will need to firstly login to your MariaDB database. To connect to our MariaDB database, we need to run

$ sudo mysql

You can now execute SQL commands, which is what we will do now:

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

This command will output all the users of our database and the authentication method they are using. You should see auth_socket on the root account.

Looking at our MariaDB users table in Termius

To change it to mysql_native_password, we will need to run this SQL query:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'securePassword';

Replace securePassword with a secure password of your choice! This is what you will use in the future to connect to your database!

Let's confirm that the password and authentication method has switched by running the same query as before:

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

You should now see that the root account will show `mysql_native_password`!

Example successful change of the authentication plugin

Now run the command EXIT; to exit the MySQL console!

From now and on you will need to use the command mysql -u root -p which lets you connect to the root user using password authentication!

- Result

Congratulations! You have installed MariaDB to your VPS, secured it and switched to the password authentication!
Was this article helpful?
Cancel
Thank you!