Halloween Edition36 maps, limited runlimited runShop the drop
Chapter 07 of 17The Server Handbook for FiveM

Database: MariaDB and oxmysql

In short

Frameworks keep players, money, items and vehicles in MariaDB (or MySQL) through oxmysql. The database is the most valuable thing on the machine — set it up properly and back it up from the first day.

Install MariaDB (Debian/Ubuntu)
sudo apt install -y mariadb-server
sudo mariadb-secure-installation
sudo mariadb
A database and a user that can only touch it
CREATE DATABASE fivem CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'fivem'@'127.0.0.1' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON fivem.* TO 'fivem'@'127.0.0.1';
FLUSH PRIVILEGES;
server.cfg
set mysql_connection_string "mysql://fivem:[email protected]/fivem?charset=utf8mb4"
set mysql_slow_query_warning 200
ensure oxmysql
  • Use a dedicated user with rights on one database only — never root.
  • Keep 3306 closed to the internet; manage the database over an SSH tunnel.
  • Import the framework’s SQL file before the first start.
  • oxmysql prints a warning for queries slower than mysql_slow_query_warning (200 ms by default). Treat each one as a bug: add an index or move the query out of a loop.
  • Index columns you search by — identifiers, citizen IDs, plates.

Schema tips for developers: FiveM database design.

The Server Handbook for FiveM

This chapter is one of 17. The handbook also carries the console command and convar cheat sheets, a glossary and the official references every chapter is checked against.

Open the handbook