NovaCloud-Hosting Docs

MariaDB Installation

Step 1: Update the system

Before installing new software, update your system:

sudo apt update
sudo apt upgrade -y

Step 2: Install MariaDB

Install the MariaDB package with the following command:

sudo apt install mariadb-server -y

Step 3: Manage the MariaDB service

Start the MariaDB service and make sure it starts automatically on boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

To check the status of the MariaDB service, use:

sudo systemctl status mariadb

Step 4: Secure the MariaDB installation

MariaDB comes with a security script that hardens the installation. Run it to configure basic security options:

sudo mysql_secure_installation

Follow the instructions. You will be prompted to do the following:

  1. Set a root password.
  2. Remove anonymous users.
  3. Disallow root login from remote machines.
  4. Remove the test database.
  5. Reload the privilege tables.

Step 5: Verify the MariaDB configuration

You can now log in to the MariaDB database to make sure everything works:

sudo mysql -u root -p

Enter the root password you set in the previous step. You should land in the MariaDB console:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Step 6: Create MariaDB users and databases

Create a new database:

CREATE DATABASE mydatabase;

Create a new user and grant them all privileges on the database:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

Leave the MariaDB console:

EXIT;

Step 7: Configure the firewall (optional)

If a firewall is enabled, you have to allow the MariaDB service if you want to access the database remotely:

sudo ufw allow 3306/tcp

Check the firewall status:

sudo ufw status

Step 8: Remote access to MariaDB (optional)

By default, MariaDB is configured to accept only local connections. To change this, edit the MariaDB configuration file:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Find the line with bind-address and change it from 127.0.0.1 to 0.0.0.0:

bind-address            = 0.0.0.0

Restart the MariaDB service to apply the changes:

sudo systemctl restart mariadb

This is a basic tutorial for installing and configuring MariaDB. There are many more options and settings you can explore to tailor MariaDB to your specific needs.

On this page