01
What oxmysql is for
FiveM can't talk to a database on its own. oxmysql is the resource that does it: frameworks (ESX, QBCore, Qbox) and most roleplay scripts go through it to read and write their data.
It replaced the older mysql-async and ghmattimysql resources, and provides their functions so old scripts keep working. On a recent server, it is the one to use, and only one at a time: don't keep the old ones running in parallel.
02
The database: MariaDB or MySQL
oxmysql works with MariaDB or MySQL. MariaDB is the most common choice for FiveM. You need:
- an empty database, created for the server;
- a user with a password, with rights on that database;
- the address of the database server (often
localhost when it runs on the same machine).
txAdmin recipes for ESX or QBCore create the database and import the tables for you. If you install a framework by hand, import the .sql file that comes with it, then those of every script that has one.
03
The connection string in server.cfg
oxmysql reads its credentials from the mysql_connection_string variable, to be placed in server.cfg:
set mysql_connection_string "mysql://utilisateur:motdepasse@localhost/mabase?charset=utf8mb4"
- replace the user, password, address and database name with your own;
- if the password contains special characters (
@, :, /…), encode them or use a password without them;
charset=utf8mb4 avoids problems with accents and emojis in character names.
This file contains a password: never share it as is, not even in a screenshot when asking for help.
04
The start order
oxmysql must start before everything that uses the database: in server.cfg, the ensure oxmysql line comes before the framework and the scripts.
ensure oxmysql
ensure ox_lib
ensure es_extended
If a script starts before oxmysql, it crashes at startup or doesn't load its data, even if the connection works.
05
Common errors
ECONNREFUSED: oxmysql can't reach the database. The MariaDB server is stopped, the address or port is wrong, or a firewall blocks it.
ER_ACCESS_DENIED_ERROR: the user or password is wrong, or the user isn't allowed to connect from that address.
ER_BAD_DB_ERROR: the database given doesn't exist. Check its name in the connection string.
ER_NO_SUCH_TABLE: a table is missing. The .sql file of the framework or script wasn't imported.
- Slow query warnings: a script queries the database too often or without indexes. The optimising a FiveM server guide helps find the culprit.
06
Backing up the database
The database is the progress of all your players. Back it up regularly, and always before a framework update or adding a script that changes the tables. An SQL export (with mysqldump or a tool such as HeidiSQL) can be restored in minutes. Keep several backups: a mistake can go unnoticed for days.
07
The database at CloudFive
Our FiveM plans include MariaDB databases, created and managed from the customer area. When you install ESX, QBCore or Qbox in one click, the database is created and server.cfg filled in for you; automatic backups also cover the database. The ESX, QBCore or Qbox guide helps you choose the framework.
08
Frequently asked questions
What is oxmysql on FiveM?
It is the resource that links the FiveM server to its MariaDB or MySQL database. The ESX, QBCore and Qbox frameworks and most roleplay scripts go through it.
Where do I put the database connection on FiveM?
In server.cfg, with the line set mysql_connection_string followed by the connection address: user, password, server address and database name.
Why can't oxmysql connect?
Most often, the database server is stopped or unreachable (ECONNREFUSED), or the user and password are wrong (ER_ACCESS_DENIED_ERROR). The console shows the exact error.
Does oxmysql replace mysql-async?
Yes. oxmysql provides the functions of mysql-async and ghmattimysql, so old scripts keep working. Use only one of these resources at a time.