# Setting up MariaDB for a FiveM server

> Set up a database for FiveM: MariaDB vs MySQL, installing on Linux and Windows, a utf8mb4 database and user, and the oxmysql connection string.

Source: https://fam-tools.com/guides/fivem-mariadb-database-setup · FAM Tools · published 2026-09-11 · updated 2026-09-11 · about 10 min

**Short answer.** Install MariaDB (`apt install mariadb-server` on Debian/Ubuntu, the MSI installer on Windows), run `mariadb-secure-installation`, then create a `utf8mb4` database and a dedicated user with rights only on it. Add `set mysql_connection_string "mysql://user:password@localhost/dbname?charset=utf8mb4"` to server.cfg and make sure oxmysql starts before your framework. Keep port 3306 closed to the internet.

## Key points

- MariaDB or MySQL 8 both work with oxmysql.
- Database charset `utf8mb4` so names with emoji do not break.
- One dedicated user per server, rights on its own database only.
- `set mysql_connection_string` (server-only, never `setr`).
- Bind to localhost; do not open 3306.

ESX, QBCore, Qbox and nearly every roleplay script store their data in a MySQL-compatible database, reached through oxmysql. Setting it up is a one-time job: install MariaDB, create a database and a user, and give oxmysql the connection string.

## Installing

*Debian / Ubuntu*

```bash
apt update && apt -y install mariadb-server
mariadb-secure-installation
```

On Windows, download the MariaDB MSI installer from mariadb.org, set a root password during setup and keep “Enable access from remote machines” off. XAMPP is fine for local testing but not for a live server.

## Creating the database and user

*mariadb -u root -p*

```sql
CREATE DATABASE fivem CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'fivem'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON fivem.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;
```

Framework recipes in txAdmin can create the database for you when you give them credentials. Either way, import the framework’s SQL files into this database.

## Connecting oxmysql

*server.cfg*

```cfg
set mysql_connection_string "mysql://fivem:a-long-random-password@localhost/fivem?charset=utf8mb4"

ensure oxmysql
ensure ox_lib
ensure qbx_core   # or es_extended / qb-core
```

Special characters in the password must be URL-encoded in this form (for example `@` becomes `%40`), or use the key-value format oxmysql also accepts. Script-side usage is in [the oxmysql guide](https://pityus.net/guides/fivem-oxmysql-guide).

## Looking inside the database

- HeidiSQL (Windows) — connect over SSH tunnel to a remote server instead of opening 3306.
- DBeaver (cross-platform) — same idea.
- phpMyAdmin — only behind a login you control, never public without protection.

## Basic tuning and safety

| Setting | Suggestion |
| --- | --- |
| `bind-address` | `127.0.0.1` so only the local machine can connect |
| `innodb_buffer_pool_size` | A good share of spare RAM (for example 1–4 GB on a dedicated game box) |
| Slow query log | Enable briefly to find slow script queries |
| Backups | Daily dumps — see [server backups](/guides/fivem-server-backups) |

## Questions

### Should I use MariaDB or MySQL for FiveM?

Either works with oxmysql. MariaDB is the common choice and easy to install.

### What is the oxmysql connection string?

`set mysql_connection_string "mysql://user:password@host/database?charset=utf8mb4"` in server.cfg.

### Why does oxmysql say access denied?

Wrong user, password or host in the connection string, or the user has no rights on that database.

### Should I open port 3306?

No. Keep the database local and use an SSH tunnel for remote tools.

## Related

- https://fam-tools.com/guides/fivem-server-backups
- https://fam-tools.com/guides/fivem-server-cfg
- https://fam-tools.com/guides/txadmin-setup-guide
- https://fam-tools.com/guides/fivem-linux-server-setup
