FiveM & GTA RPConnect MySQL to a FiveM Server with oxmysql
Link your MySQL database to FiveM with oxmysql: connection string, start order in server.cfg, importing the ESX or QBCore schema and common errors.
A roleplay FiveM server cannot run without a database: players, vehicles, inventories, money, everything is stored there. oxmysql is the resource that links your scripts to MySQL. This guide covers the install, the connection string and the start order - the three places where it all happens.
⚙️ Requirements
- A Lordhosting FiveM server, reachable from the panel
- A MySQL or MariaDB database with its user and password
- A framework installed: ESX or QBCore - see ESX vs QBCore
- SFTP access or the panel file manager
⚙️ 1. Install oxmysql
Download the latest version from the overextended/oxmysql repository (the oxmysql.zip file on the Releases page, not the source archive). Extract it, then drop the folder into resources/:
resources/
├── [standalone]/
│ └── oxmysql/
├── [core]/
└── [scripts]/
The folder name must stay exactly oxmysql: other resources call it by that name.
⚙️ 2. Write the connection string
In server.cfg, add this line before any ensure:
set mysql_connection_string "mysql://user:[email protected]:3306/fivem?charset=utf8mb4"
The key-value syntax also works and reads better when the password holds special characters:
set mysql_connection_string "server=127.0.0.1;database=fivem;userid=user;password=password;charset=utf8mb4"
In the mysql:// form, an @, a : or a / inside the password breaks URL parsing. Use the key-value syntax, or percent-encode the character (@ becomes %40).
⚙️ 3. Respect the start order
oxmysql must load before the framework, which must load before the scripts:
ensure oxmysql
ensure es_extended # or qb-core
ensure your-script
An ensure oxmysql placed after the framework produces oxmysql was not found, even when the resource is correctly installed. By far the most common cause.
⚙️ 4. Import the framework schema
Each framework ships its .sql files. Import them in the order its documentation gives, with phpMyAdmin or on the command line:
mysql -u user -p fivem < es_extended.sql
Then check the tables are there:
SHOW TABLES;
SELECT COUNT(*) FROM users;
An empty database when the framework starts produces Unknown column errors as soon as a player connects.
⚙️ 5. Verify the connection
Start the server and read the console. oxmysql states its status clearly:
[oxmysql] Database server connection established
From the server console, two useful commands:
set mysql_debug true
Debug mode logs every query with its duration - valuable for spotting a script hammering the database in a loop. Turn it off in production, it fills the logs.
⚙️ 6. Fix the common errors
Unable to establish a connection to the database: wrong credentials or database name. Test them with a MySQL client from the same machine.oxmysql was not found: start order, or a misnamed folder.ER_NOT_SUPPORTED_AUTH_MODE: the MySQL 8 user usescaching_sha2_password. Switch it tomysql_native_password.Too many connections: a resource opens connections without releasing them. Debug mode identifies the culprit.- Broken accents in game:
charset=utf8mb4missing from the connection string.
A query over 200 ms running on every tick drags the server down. oxmysql's debug mode shows durations: it is the first place to look when the server lags for no obvious reason.
⚙️ Ready-to-paste configuration
Three blocks: the database, the resource, the check.
1. Create the database, on the MySQL server - replace the password with a generated one (openssl rand -base64 24):
CREATE DATABASE IF NOT EXISTS fivem
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS 'fivem'@'localhost' IDENTIFIED BY 'MY_PASSWORD';
GRANT ALL PRIVILEGES ON fivem.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;
2. The server.cfg block, in exactly this order - connection string before any ensure, oxmysql before the framework, the framework before the scripts:
# ---- Database ------------------------------------------------------------
# Key-value form: preferable as soon as the password contains @ : / or #
set mysql_connection_string "server=127.0.0.1;database=fivem;userid=fivem;password=MY_PASSWORD;charset=utf8mb4"
# ---- Start order ---------------------------------------------------------
ensure oxmysql # always first
ensure es_extended # or qb-core
ensure your-script # your resources after that
3. The check, in the server console at startup:
# The line you want to see in the console
[oxmysql] Database server connection established
# Measure slow queries while diagnosing
set mysql_debug true
And the test outside the game, which separates a credentials problem from a resource problem:
# If this command works, the database and account are fine:
# anything left is a server.cfg or start-order problem
mysql -u fivem -p -h 127.0.0.1 fivem -e "SELECT COUNT(*) FROM users;"
server.cfg holds the connection string in plain text. If you version your server, keep that file out of the repository, or move the line into a separately included file.
✅ Conclusion
Your database is linked to FiveM, the schema is imported and the start order is right. Continue with configuring server.cfg and installing txAdmin for day-to-day administration.
Our FiveM servers include a MySQL database on the same infrastructure: latency between the game server and the database stays below a millisecond.

