Connect a MySQL Database to FiveM
How to connect your server to database for data storage
Storing player info, money, and properties requires a database. oxmysql is currently the standard and fastest option.
- 1Step 1
Create Database
Access phpMyAdmin and create a new database (e.g., fivem_server). Remember the name.
- 2Step 2
Download oxmysql
Download the latest oxmysql and put it in resources. Ensure it starts before any script needing data.
- 3Step 3
Setup Connection String
In server.cfg, add the connection line: set mysql_connection_string 'server=localhost;database=fivem_server;userid=root;password=yourpassword'
# server.cfg: before your framework set mysql_connection_string "mysql://fivem_user:strong_password@localhost/fivem?charset=utf8mb4" ensure oxmysql - 4Step 4
Import Tables
If using a Base pack, import the included .sql file into your database.
Database Tips
- Always use oxmysql instead of the old mysql-async for better performance.
- Ensure no extra spaces in the connection string.
- Backup your database regularly.
- Protect your database with a strong password and don't share it.
Frequently asked questions
MySQL or MariaDB for FiveM?
Both work with oxmysql. MariaDB is a common choice on game servers; what matters more is that the database runs on the same machine or very close to the FiveM server.
oxmysql says it cannot connect. What should I check?
That the database service is running, that the user, password and database name in mysql_connection_string are correct, and that the host and port (3306 by default) are reachable from the server.
Should I open port 3306 to the internet?
No. Keep the database on localhost or a private network. Opening it publicly invites password-guessing attacks and is not needed for players.
Why must oxmysql start before the framework?
ESX and QBCore load player data from the database as soon as they start. If oxmysql is not running yet, they fail or run without data, so ensure oxmysql first.
Run this guide on a ready server
Need a server for this guide? FiveM server hosting from SNG comes with txAdmin, OneSync and DDoS protection, and the SNG CDN for FiveM delivers your server files to players from inside Saudi Arabia.
Related FiveM guides
Database connection issues?
