FiveMMySQLDatabase4 min read

Configure MySQL database for FiveM

Set up MariaDB/MySQL and connect it to your FiveM server with oxmysql.


Why MariaDB?

FiveM roleplay frameworks (ESX, QBCore) store player data, vehicles, inventories and jobs in a relational database. MariaDB is the standard choice for FiveM servers — it's fast, reliable and fully compatible with MySQL.

Step 1: Install MariaDB

Connect to your VPS via SSH and install MariaDB:

bash
sudo apt update
sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable mariadb
sudo systemctl start mariadb

Step 2: Secure the installation

Run the security script:

bash
sudo mysql_secure_installation
  • Set a root password
  • Remove anonymous users: Yes
  • Disallow root login remotely: Yes
  • Remove test database: Yes
  • Reload privilege tables: Yes

Step 3: Create the FiveM database and user

bash
sudo mysql -u root -p

Inside the MySQL shell:

sql
CREATE DATABASE fivem_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'fivem'@'localhost' IDENTIFIED BY 'YourSecurePassword123';
GRANT ALL PRIVILEGES ON fivem_db.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Install oxmysql

oxmysql is the standard MySQL connector for FiveM:

bash
cd ~/fxserver/server-data/resources/
git clone https://github.com/overextended/oxmysql.git

Or download the latest release from the GitHub releases page.

Step 5: Configure the connection string

In your server.cfg, add:

bash
ensure oxmysql

set mysql_connection_string "mysql://fivem:YourSecurePassword123@localhost/fivem_db?waitForConnections=true&connectionLimit=10"

Important: ensure oxmysql must be one of the first resources loaded, before any framework.

Step 6: Verify the connection

Restart the server from txAdmin. In the console you should see:

terminal
[oxmysql] Connected to database: fivem_db

If you see connection errors, verify:

  • The password is correct
  • MariaDB is running (systemctl status mariadb)
  • The user has proper permissions

Performance tuning

Edit /etc/mysql/mariadb.conf.d/50-server.cnf:

ini
[mysqld]
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
max_connections = 100
query_cache_type = 1
query_cache_size = 32M

Restart MariaDB:

bash
sudo systemctl restart mariadb

Backup your database

Set up a daily backup cron job:

bash
crontab -e

Add:

bash
0 4 * * * mysqldump -u fivem -pYourSecurePassword123 fivem_db | gzip > /home/fivem/backups/fivem_db_$(date +\%Y\%m\%d).sql.gz

Tips

  • Use connectionLimit=10 as a starting point; increase if you have many scripts querying simultaneously
  • Monitor slow queries with SET GLOBAL slow_query_log = 'ON';
  • Never expose MariaDB to the internet (keep it on localhost)
  • Use phpMyAdmin or HeidiSQL for visual database management via SSH tunnel

Was this guide helpful?