MariaDB is a popular open-source relational database management system that is a fork of MySQL. It is widely used for its performance, stability, and compatibility with MySQL. This tutorial will guide you through the process of installing MariaDB on an Ubuntu 22.04 server as the root user.
Step 1: Deploying a Cloud Instance on Shape.host
- Log in to Shape.host Dashboard:
- Navigate to the Shape.host website and log in to your account.
- Create a New Instance:
- Click on the “Create” button located at the top right corner of the dashboard.
- From the dropdown menu, select “Instances”.

- Select Instance Location:
- Choose the desired location for your server. For this tutorial, we’ll select “New York, USA”.

- Choose a Plan:
- Select a plan that fits your requirements. For example, you might choose a plan with 2 cores CPU, 2 GB Memory, and 50 GB SSD disk space.
- Select an Operating System:
- Scroll down to the “Choose an image” section and select “Ubuntu 22.04”.

- Configure Additional Options:
- (Optional) You can configure additional options like User Data Configuration and IPv6 Networking.
- Enter a hostname for your instance, e.g., “Tutorial Ubuntu”.
- Click on the “Create instance” button to deploy the instance.

Step 2: Connecting to Your Instance
- Retrieve SSH Credentials:
- Note the IP address of your newly created instance from the Shape.host dashboard.
- Connect via SSH:
- Open a terminal on your local machine.
- Use the following command to connect to your instance:
sh ssh root@your_instance_ip
- Replace
your_instance_ip
with the actual IP address of your instance.
Step 3: Updating the System
Before installing MariaDB, it’s a good idea to update your system to ensure all existing packages are up-to-date. Open your terminal and run the following commands:
apt update
apt upgrade

This will update the package lists and install the latest versions of all packages currently installed on your system.
Step 4: Installing MariaDB
MariaDB is available in the default Ubuntu repositories, so the installation process is straightforward. Use the following command to install MariaDB:
apt install mariadb-server

Step 5: Starting and Enabling MariaDB
Once the installation is complete, MariaDB should be automatically started. You can verify its status with:
systemctl status mariadb


You should see an output indicating that the MariaDB service is active and running. To enable MariaDB to start on boot, use the following command:
systemctl enable mariadb
Step 6: Securing MariaDB
MariaDB includes a security script to change some of the default settings to increase security. Run the following command to start the script:
mysql_secure_installation

You will be prompted to enter the current root password. Since this is a fresh installation, press ENTER
as there is no current password set. Then, follow the prompts to set a root password and secure your installation. The script will guide you through:
- Setting a root password
- Removing anonymous users
- Disallowing remote root login
- Removing the test database
- Reloading the privilege tables
For each prompt, press Y
and ENTER
to accept the default suggestions.

Step 7: Testing MariaDB
After securing MariaDB, you can test the installation by logging in to the MariaDB shell:
mysql -u root -p

You will be prompted to enter the root password you set during the secure installation process. After logging in, you will see the MariaDB shell prompt:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.5.9-MariaDB-1:10.5.9+maria~focal mariadb.org binary distribution
MariaDB [(none)]>
To exit the MariaDB shell, type:
exit

Step 8: Creating a New Database and User
To create a new database and user, follow these steps:
Log in to the MariaDB shell as the root user:
mysql -u root -p

Create a new database:
CREATE DATABASE mydatabase;
Create a new user and grant privileges:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Exit the MariaDB shell:
exit

Step 9: Configuring Remote Access (Optional)
By default, MariaDB only allows connections from the localhost. To allow remote connections, you need to configure MariaDB to listen on all IP addresses and allow remote access to the database.
Edit the MariaDB configuration file:
nano /etc/mysql/mariadb.conf.d/50-server.cnf

Find the line starting with bind-address
and change it to:
bind-address = 0.0.0.0

Next, you need to create a new user with access permissions for remote connections. Log in to the MariaDB shell:
mysql -u root -p

Create a new user and grant remote access privileges:
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'%';
FLUSH PRIVILEGES;
Exit the MariaDB shell:
exit

Restart MariaDB to apply the changes:
systemctl restart mariadb

In this tutorial, you have learned how to install and configure MariaDB on an Ubuntu 22.04 server using the root user. You now have a powerful relational database system ready for use in your applications. For further reading and advanced configurations, refer to the official MariaDB documentation.
For reliable hosting solutions, consider using Shape.host services. They offer Linux SSD VPS, providing high performance and stability for your MariaDB server.