In short
To set up oxmysql in FiveM, create a MariaDB database and user with the utf8mb4 character set, add a set mysql_connection_string line to server.cfg, and place ensure oxmysql before your framework. Then import your framework's SQL files with HeidiSQL. A connection refused error usually means MariaDB isn't running, the host or port is wrong, or bind-address only allows local connections.
In this guide
- What are oxmysql and MariaDB?
- Step 1: Create the database and user
- Step 2: The mysql_connection_string format
- Step 3: Add the oxmysql resource and set the load order
- Step 4: Connect with HeidiSQL and import SQL
- Common errors and fixes
- Performance and security tips
- RAM and CPU: the database uses resources too
- Next step: start with a database-ready server
On a FiveM server, player characters, inventories, vehicles and money all live in a database. Today, the bridge between that database and the server in almost every ESX, QBCore and QBox setup is the oxmysql resource. In short, here's what you need to do: create a database and user in MariaDB, add the connection details to server.cfg as mysql_connection_string, start the oxmysql resource before your framework, and import your framework's SQL files. Below we walk through each step, along with the most common errors.
What are oxmysql and MariaDB?
MariaDB is an open-source, MySQL-compatible relational database server that listens on TCP port 3306 by default. oxmysql is a FiveM resource that lets Lua scripts on your FiveM server send queries to that database; it replaced the older mysql-async and ghmattimysql resources. Scripts call functions like MySQL.query and MySQL.insert, and oxmysql passes those queries to MariaDB through a connection pool.
Why MariaDB? Most ready-made SQL files in the FiveM community are tested against MariaDB, it's lightweight to install, and it accepts MySQL syntax as-is. MySQL 8 works too, but if you're starting fresh, MariaDB lowers the chance of running into problems.
Step 1: Create the database and user
In your game panel
If you're using a managed FiveM game server, you can usually create a database in one click from the panel's Databases section. The panel gives you a host address, port, database name, username and password; write these down. If you're installing with a txAdmin recipe, txAdmin asks for these details during setup and creates the tables for you. If you don't see a Databases section, open a support ticket and request one.
On your own VDS (Linux)
On an Ubuntu or Debian server, install and secure MariaDB with these commands:
sudo apt update
sudo apt install mariadb-server -y
sudo systemctl enable --now mariadb
sudo mariadb-secure-installationThen open the MariaDB console (sudo mariadb) and create the database plus a user that only has rights on that database:
CREATE DATABASE fivem CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'fivem'@'localhost' IDENTIFIED BY 'GucluBirSifre_123';
GRANT ALL PRIVILEGES ON fivem.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;The utf8mb4 character set matters: character names with non-English letters (such as the Turkish Ş, Ğ, İ) and data containing emoji are only stored reliably with this set. Don't use the root user for FiveM, so a single script vulnerability can't put your entire database server at risk.
On your own VDS (Windows)
On a Windows server, just download and run MariaDB's official MSI installer. The setup wizard asks for a root password, registers MariaDB as a Windows service and can optionally install HeidiSQL alongside it. Leave the Enable access from remote machines for root user option unchecked; if you need remote management, create a separate user. After installation, run the SQL commands above in HeidiSQL's query window to create the database and user. If the database and FiveM run on the same machine, you don't need to open port 3306 in Windows Firewall.
Step 2: The mysql_connection_string format
oxmysql reads its connection details from the mysql_connection_string convar in server.cfg. There are two valid formats:
# URI format (recommended)
set mysql_connection_string "mysql://fivem:GucluBirSifre_123@127.0.0.1:3306/fivem?charset=utf8mb4"
# Key=value format
set mysql_connection_string "user=fivem;password=GucluBirSifre_123;host=127.0.0.1;port=3306;database=fivem;charset=utf8mb4"Keep these points in mind:
- If your password contains characters like
@,:,/,#or%, you must URL-encode them in the URI format (for example,%40instead of@). The practical fix: use the key=value format, or avoid these characters in the password. - If the database is on the same machine, use
127.0.0.1as the host. On a game panel, use the exact host address the panel gives you. - Your
ensurelines must come after this line; the convar has to be defined before the resource starts.
Step 3: Add the oxmysql resource and set the load order
Download the compiled build of oxmysql from its official GitHub Releases page and place it in your resources folder as oxmysql. Make sure you grab the compiled package, not the "Source code" archive, or the resource won't start. Then set up your server.cfg order like this:
set mysql_connection_string "mysql://fivem:GucluBirSifre_123@127.0.0.1:3306/fivem?charset=utf8mb4"
set mysql_slow_query_warning 150
set mysql_ui true
ensure oxmysql
ensure ox_lib
ensure es_extended # or qb-core / qbx_core
# other scripts after thismysql_slow_query_warning prints a console warning for any query that takes longer than the given number of milliseconds. With mysql_ui enabled, authorized players can use the /mysql command to see how many queries each resource sends. The ordering rule is simple: every script that touches the database must start after oxmysql. For the full set of server.cfg lines, see our FiveM server.cfg settings guide.
Step 4: Connect with HeidiSQL and import SQL
HeidiSQL is a free database management tool for Windows and the most widely used client in the FiveM community.
- Open HeidiSQL and create a session with the New button in the bottom left.
- Set Network type to MariaDB or MySQL (TCP/IP).
- Fill in Hostname / IP, User, Password and Port (usually 3306) with the details from your panel or the ones you created.
- Click Open and select your database in the list on the left.
- From File > Run SQL file, pick your framework's SQL file (for example, the
.sqlinsidees_extendedfor ESX, orqbcore.sqlfor QBCore). - Then run the SQL files for any additional scripts one by one. If a line throws an error, read the message; most of the time the table already exists.
To connect remotely, the database has to accept external connections. If you're doing this on your own VDS, don't open port 3306 to everyone; allow only your own IP address in the firewall, or use HeidiSQL's SSH tunnel option.
Common errors and fixes
| Console message | What it means | Fix |
|---|---|---|
ECONNREFUSED / connection refused | No database is listening on the given host and port | Check that the MariaDB service is running (systemctl status mariadb) and verify the host and port |
ER_ACCESS_DENIED_ERROR | Wrong username or password, or the user isn't allowed to connect from this host | Check the password and any special characters; see whether the user was defined as 'fivem'@'localhost' or 'fivem'@'%' |
ER_BAD_DB_ERROR | Database name not found | Check the database name in the connection string, including upper/lowercase |
ER_NO_SUCH_TABLE | The table doesn't exist | You haven't imported that script's SQL file |
ETIMEDOUT | The server can't be reached | Firewall on the remote database or wrong IP |
Connection refused checklist
- Is MariaDB actually running? Check with
sudo systemctl status mariadbon Linux, or in the Services console on Windows. - Is it listening on the right port? You should see a line in the output of
sudo ss -tlnp | grep 3306. - If the database is on a different machine, the
bind-addressvalue in the MariaDB config may be127.0.0.1; in that case it only accepts local connections. - If you used
localhost, try127.0.0.1instead; on some systems localhost resolves to an IPv6 address. - If you're on a panel, make sure the host is the address the panel gave you; your own computer's address won't work there.
If your server won't start at all because of a database error, our FiveM "Couldn't Start Resource" errors guide covers resource startup problems in more detail.
Performance and security tips
- Monitor your queries: A script that triggers slow query warnings is usually hitting a table with a missing index; adding the right index to that table is often all it takes.
- Don't query inside loops: A script that writes to the database every second wears down the server thread as your player count grows.
- Back up: The database is the most valuable part of your server. For regular
mysqldumpbackups, see our FiveM backup guide. - Use a separate user: Give the FiveM user privileges only on its own database.
RAM and CPU: the database uses resources too
When the database runs on the same server, it shares RAM and CPU with FiveM. On a small server with few resources, that's negligible, but as you add inventory, phone, garage and logging scripts, the query count climbs noticeably. As a rough guide, for a roleplay server running a framework plus 50 or more scripts, 6 GB of RAM or more is a comfortable starting point so the database and the game server don't squeeze each other.
Next step: start with a database-ready server
Trying the setup on your own machine is a great way to learn, but a live community needs solid infrastructure. OyunBulut's OB-FIVEM-3 FiveM server with 4 CPU and 6 GB DDR5 RAM comes with a 60 GB NVMe disk, DDoS protection and automatic setup; it's a mid-tier plan that comfortably runs your framework, oxmysql and the database side by side. If you need something smaller or larger, compare every option on the FiveM server plans page. If you get stuck during setup, you can open a support ticket for your Istanbul-based servers; to get started, just pick the OB-FIVEM-3 plan and apply the server.cfg lines from this guide.
Frequently asked questions
Should I use oxmysql or mysql-async?
Use oxmysql for new setups. mysql-async is no longer maintained, while oxmysql is the default database resource in current ESX, QBCore and QBox releases and is largely compatible with older function calls.
Where do I put mysql_connection_string?
Add it to server.cfg as set mysql_connection_string "...", before the ensure oxmysql line. The convar must be defined before the resource starts.
What causes the FiveM connection refused error?
It happens when no database is running on the given host and port. Check that the MariaDB service is up, that the port is 3306, and, for remote connections, your bind-address and firewall settings.
What character set should the database use?
utf8mb4 with utf8mb4_unicode_ci is recommended. It stores non-English characters and emoji reliably, while the older utf8 set can throw errors on some characters.
How do I import an SQL file with HeidiSQL?
After connecting, select your database in the list on the left and open the .sql file with File > Run SQL file. Run the framework's SQL first, then the SQL files for your additional scripts.