Skip to content

Set Up MariaDB on a Linux Server – Run Your Own MySQL-Compatible Database

Set up MariaDB as a One-Click App or with Docker Compose on your Linux server. Learn how to manage credentials, connect, secure access, and create backups.

26 November 20265 min read2 Views0 helpful

Introduction

MariaDB is a MySQL-compatible open-source database. Many applications require it, including websites, FiveM frameworks with oxmysql, Minecraft plugins like LuckPerms, and your own projects. With your own MariaDB server on your VPS, you decide which databases and users exist and who can access them.

In this guide, we’ll show you two ways to set it up: the easy way as a One-Click App, which automatically creates a database, user, and passwords, and the manual installation using Docker Compose on a Linux server.

The Easy Way: MariaDB as a One-Click App

With your VPS’s One-Click Apps, you can launch a standalone MariaDB server running version 11.8 (LTS). During installation, the app creates a database, a user, and secure passwords. The database is then accessible through your VPS’s IP address, and its data is stored persistently.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. For instructions, see VPS: One-Click Apps.
  • At least 512 MB RAM for MariaDB; 1 GB is recommended. Larger databases require more.
Info

Do you actually need a separate database app? Many apps include their own database, such as ZAP Webspace with MariaDB and phpMyAdmin for your website. See Web Hosting: Set Up a Website with ZAP Webspace. The MariaDB app is intended for cases where a database needs to be accessible from outside, such as for a game server or an application on another server.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search for “MariaDB” in the App catalog and click Install next to MariaDB.
  3. Under App configuration, you can change two values. This is optional:
FieldDefaultDescription
MARIADB_DATABASEappName of the database created during installation
MARIADB_PORT3306Port used to access the database from outside
  1. Click Queue installation. After about a minute, the app will be Online.

You don’t need a domain of your own; MariaDB doesn’t have a web interface. The app’s card shows the address where your database can be reached under Connection, for example, 123.123.123.123:3306.

Find Your Credentials

The app generates users and passwords during installation. You can find them in the app’s settings (gear icon), under App environment > Automatically generated values. Click the eye icon to reveal a value or the copy icon to copy it.

ValueDescription
SERVICE_USER_MARIADBUsername for your database; the default is zapx
SERVICE_PASSWORD_MARIADBPassword for this user
SERVICE_PASSWORD_MARIADBROOTPassword for the root user

The zapx user has full access to the app database and cannot see any other databases. Use the root user to create additional databases and users, for example, in phpMyAdmin.

Connect to the Database

You’ll need the following details for each application that will use your database:

SettingValue
HostIP address of your VPS
Port3306 or the value of MARIADB_PORT
Databaseapp or the value of MARIADB_DATABASE
Username and passwordSERVICE_USER_MARIADB and SERVICE_PASSWORD_MARIADB

For a FiveM server with oxmysql, the line in server.cfg would look like this, for example:

Code
set mysql_connection_string "mysql://zapx:DEIN_PASSWORT@123.123.123.123:3306/app?charset=utf8mb4"

You can add a web interface for your database using the phpMyAdmin One-Click App. Enter your VPS’s IP address as the server. This also works when both apps are running on the same VPS. For instructions, see Set Up phpMyAdmin on a Linux Server.

Secure Access

The database is accessible over its port from anywhere on the internet. The generated passwords are long and random, but you should still restrict access: Create a rule under Network firewall on your VPS that only allows the database port to be accessed by the IP addresses that need to connect, such as your game server’s IP address.

Backups, Updates, and Uninstalling

  • Backups: Export a backup of your database in phpMyAdmin using the Export tab, or on your own computer with mariadb-dump -h 123.123.123.123 -u zapx -p app > backup.sql.
  • Updates: Open the app’s settings (gear icon) > App update and click Check for updates. If a new version is available, install it by clicking Apply update. Your data will be preserved.
  • Uninstalling: When uninstalling under App actions > Uninstall app, you can also delete the data volumes. This permanently deletes all databases. Create a backup first.

Manual Installation

The rest of this guide describes the manual installation of MariaDB 11.8 using Docker Compose on a Linux server, for example, on a dedicated server or if you want to configure everything yourself. This is based on the official guide to the MariaDB Docker image.

Info

Install MariaDB without Docker If you want to install MariaDB directly using your system’s package manager, follow the steps in Set Up Databases on a Linux Server.

Preparation

Docker and Docker Compose must be installed on your server. For instructions, see Set Up Docker on a Linux Server. Then create a folder for MariaDB and navigate to it:

Code
mkdir -p /opt/mariadb && cd /opt/mariadb

Configuration

Create the docker-compose.yml file with the following content using nano docker-compose.yml. Replace the passwords with your own secure values:

Code
services:
  mariadb:
    image: mariadb:11.8
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ein-sicheres-root-passwort
      MARIADB_DATABASE: app
      MARIADB_USER: appuser
      MARIADB_PASSWORD: ein-sicheres-passwort
    ports:
      - "3306:3306"
    volumes:
      - mariadb-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 10

volumes:
  mariadb-data:

On its first start, MariaDB creates the app database and the appuser user with full access to that database. The data is stored in the mariadb-data Docker volume and is preserved when you recreate the container.

Warning

Only make the database accessible from outside if necessary With ports, the database is accessible from the internet on port 3306. If only an application on the same server uses the database, use "127.0.0.1:3306:3306" instead. Otherwise, use your firewall to restrict access to the port to the required IP addresses.

Start and Test

Start MariaDB in the background and check its status:

Code
docker compose up -d
docker compose ps

Once the container is shown as healthy, log in to test it:

Code
docker compose exec mariadb mariadb -u appuser -p app

Use exit to leave the database console.

Back Up and Update

Create a backup of all databases as follows:

Code
docker compose exec -T mariadb sh -c 'mariadb-dump --all-databases -uroot -p"$MARIADB_ROOT_PASSWORD"' > backup.sql

To update within version 11.8, download the new image and recreate the container:

Code
docker compose pull
docker compose up -d

If you want to upgrade to a new major version later, create a backup first, change the version in image, and add the MARIADB_AUTO_UPGRADE: "1" line under environment. MariaDB will then update the system tables automatically on startup.

Conclusion

With the One-Click App, you can have your own MariaDB database with ready-to-use credentials in a minute. With Docker Compose, you can set it up yourself in just a few steps. Secure access with a firewall and create regular backups. If you need help, our support team will be happy to assist.

Free tools

Related tools for servers and developers

View all

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.