How To Install MariaDB on Ubuntu 20.04 In Digitalocean

October 19, 2023 0 Comments

Introduction:

MariaDB is an open-source relational database management system, commonly used as an alternative for MySQL as the database portion of the popular LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. It is intended to be a drop-in replacement for MySQL.

The short version of this installation guide consists of these three steps:

Update your package index using apt
Install the mariadb-server package using apt. The package also pulls in related tools to interact with MariaDB
Run the included mysql_secure_installation security script to restrict access to the server

sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation

Step 1 — Installing MariaDB:

As of this writing, Ubuntu 20.04’s default APT repositories include MariaDB version 10.3.

To install it, update the package index on your server with apt:

sudo apt update

Then install the package:

sudo apt install mariadb-server

Ensure that MariaDB is running with the systemctl start command:

sudo systemctl start mariadb.service

Step 2 — Configuring MariaDB:

Tailor your branding to resonate with your target audience. Understand their needs, preferences, and aspirations. Crafting a brand that aligns with the values and interests of your audience creates a connection that goes beyond transactional relationships.

For new MariaDB installations, the next step is to run the included security script. This script changes some of the less secure default options for things like remote root logins and sample users.

sudo mysql_secure_installation

Output
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
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

The next prompt asks you whether you’d like to set up a database root password. On Ubuntu, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Type N and then press ENTER.

Output
. . .
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] N

Step 3 — (Optional) Creating an Administrative User that Employs Password Authentication:

To this end, we will create a new account called admin with the same capabilities as the root account, but configured for password authentication. Open up the MariaDB prompt from your terminal:

sudo mariadb

GRANT ALL ON *.* TO ‘admin’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

FLUSH PRIVILEGES;

exit

Step 4 — Testing MariaDB:

When installed from the default repositories, MariaDB will start running automatically. To test this, check its status.

sudo systemctl status mariadb

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

Output
● mariadb.service – MariaDB 10.3.22 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-05-12 13:38:18 UTC; 3min 55s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 25914 (mysqld)
Status: “Taking your SQL requests now…”
Tasks: 31 (limit: 2345)
Memory: 65.6M
CGroup: /system.slice/mariadb.service
└─25914 /usr/sbin/mysqld
. . .

Conclusion:

In this guide you installed the MariaDB relational database management system, and secured it using the mysql_secure_installation script that it came installed with. You also had the option to create a new administrative user that uses password authentication before testing the MariaDB server’s functionality.

Leave A Comment

To Top