Find us on social media
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:
sudo apt update
sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable mariadb
sudo systemctl start mariadbStep 2: Secure the installation
Run the security script:
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
sudo mysql -u root -pInside the MySQL shell:
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:
cd ~/fxserver/server-data/resources/
git clone https://github.com/overextended/oxmysql.gitOr download the latest release from the GitHub releases page.
Step 5: Configure the connection string
In your server.cfg, add:
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:
[oxmysql] Connected to database: fivem_dbIf 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:
[mysqld]
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
max_connections = 100
query_cache_type = 1
query_cache_size = 32MRestart MariaDB:
sudo systemctl restart mariadbBackup your database
Set up a daily backup cron job:
crontab -eAdd:
0 4 * * * mysqldump -u fivem -pYourSecurePassword123 fivem_db | gzip > /home/fivem/backups/fivem_db_$(date +\%Y\%m\%d).sql.gzTips
- Use
connectionLimit=10as 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