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.
Build it
Create a database
Open HeidiSQL, connect to MariaDB (Host: 127.0.0.1, User: root, Port: 3306). Right-click the server → Create new → Database. 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
Place oxmysql in your resources folder, then add to server.cfg:
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 usernameYOUR_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:
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:
[oxmysql] Connection Successful
Understand SQL files
Most FiveM scripts include a .sql file. This file creates the tables the script needs.
Example users.sql:
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
In HeidiSQL:
- Select your database (
fivem_db) on the left - Click File → Load SQL file (or drag the
.sqlfile into the query window) - Review the SQL - understand what tables it creates
- Click Execute (the blue triangle)
- 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
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, noAccess denied, and noTable '...' 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 existline means you skipped or misnamed the.sqlimport. Go back to Step 4 and import it into the right database. - A
Connection FailedorAccess deniedline means themysql_connection_stringis 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.
- The database install workflow
- Common failures
The remainder of Databases, oxmysql, and SQL importing is available to FiveM School members.