Skip to main content
TRACK A·RESOURCES AND DATABASE·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

FiveM databases, oxmysql, and SQL importing

The server is the game world. The database is its memory. Without a database, players lose everything - money, vehicles, characters, houses - every time the server restarts. This lesson connects FiveM to MariaDB using oxmysql, the modern standard for database access.

You'll do
Connect FiveM to MariaDB via oxmysql, import a script's SQL, and verify by booting the real script clean.
Time
~30 minutes
You need
A local FiveM server, MariaDB installed (see the tools lesson), and HeidiSQL.
You'll learn
What a database is, why servers need them, the MariaDB → oxmysql → FiveM chain, the mysql_connection_string convar in both forms, importing SQL files, and the resource-install database workflow.
BEFORE YOU START

Build it

Create a database

An empty database is ready to receive tables.

Open HeidiSQL, connect to MariaDB (Host: 127.0.0.1, User: root, Port: 3306). Right-click the server → Create newDatabase. Name it fivem_db.

A database is a container for tables. It starts empty. Scripts create tables inside it when you import their SQL files.

Install oxmysql and connect

The server console says 'Connection Successful'.

Place oxmysql in your resources folder, then add to server.cfg:

code
ensure oxmysql

set mysql_connection_string "mysql://root:[email protected]/fivem_db"
set mysql_slow_query_warning 150

The mysql_connection_string convar is how oxmysql reaches your database. Breaking down the URI form above:

  • root - your MariaDB username
  • YOUR_PASSWORD - your MariaDB password (leave empty if you didn't set one)
  • 127.0.0.1 - where MariaDB lives (localhost = same machine)
  • fivem_db - the database name you created in Step 1

There are two accepted forms of this convar. The URI form above is the common one. The semicolon form spells out each field by name and is easier to read:

code
set mysql_connection_string "user=root;password=YOUR_PASSWORD;host=127.0.0.1;port=3306;database=fivem_db"

Use the semicolon form when your password contains a special character. The oxmysql docs list characters to avoid inside the URI form's password: ; , / ? : @ & = + $ #. If your root password contains any of those, the URI form can misparse and the connection fails. Either switch to the semicolon form (or change the password to plain letters and numbers).

Character encoding is not set in the connection string. oxmysql does not document a ?charset= parameter here. You set the encoding on the database itself: create it as utf8mb4 (for example utf8mb4_unicode_ci) so accented player names and emoji store correctly.

Restart the server. Watch the console for the magic line:

code
[oxmysql] Connection Successful

Understand SQL files

You know what a .sql file does and why scripts ship them.

Most FiveM scripts include a .sql file. This file creates the tables the script needs.

Example users.sql:

code
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
money INT DEFAULT 500,
job VARCHAR(50) DEFAULT 'unemployed'
);

This creates a table called users with four columns: id, name, money, and job. The table is the skeleton - rows of data fill it later. Without importing this file, the script's database queries will fail because the table doesn't exist.

Import an SQL file

New tables appear in HeidiSQL.

In HeidiSQL:

  1. Select your database (fivem_db) on the left
  2. Click File → Load SQL file (or drag the .sql file into the query window)
  3. Review the SQL - understand what tables it creates
  4. Click Execute (the blue triangle)
  5. Right-click the database → Refresh

New tables should appear. Common table names: users, players, owned_vehicles, jobs, houses, ox_inventory.

Verify by booting the real script

The script that needs the database starts clean.

An owner does not write a test query to prove the database works. You prove it the way you will do it for every install: import the script's .sql, then ensure the real script and watch the console.

Add the script below oxmysql in server.cfg, then in the txAdmin Live Console run refresh and ensure the-script-name. Read the console:

  • A clean start line for the script, with no [oxmysql] Connection Failed, no Access denied, and no Table '...' doesn't exist, means the whole chain works: MariaDB is up, oxmysql reached it, and the tables the script needs are present.
  • A Table '...' doesn't exist line means you skipped or misnamed the .sql import. Go back to Step 4 and import it into the right database.
  • A Connection Failed or Access denied line means the mysql_connection_string is wrong. Recheck the user, password, host, and database name against what HeidiSQL connects with.

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • The database install workflow
  • Common failures

The remainder of Databases, oxmysql, and SQL importing is available to FiveM School members.