How to Connect MariaDB to Your FiveM Server: A Step-by-Step Guide

Image Source: Freepik

Want to level up your FiveM server by using a proper database system? Connecting MariaDB to your FiveM server is the key to unlocking scalable, reliable, and persistent data management. Whether you want to store player information, job stats, or server logs, MariaDB can handle it efficiently.

In this beginner-friendly guide, we’ll walk you through the entire setup process. No complicated jargon. Just clear steps to get your FiveM server talking to MariaDB like a pro.

What Is MariaDB and Why Use It with FiveM?

MariaDB is a free, open-source database system derived from MySQL. It offers high performance, scalability, and flexibility, making it perfect for storing server-side data.

In FiveM, MariaDB allows you to:

  • Store player data (money, inventory, position, etc.)
  • Manage user permissions and whitelists
  • Log events and system interactions
  • Handle jobs, businesses, and in-game economies

Using a database like MariaDB moves you away from slow, clunky flat files and gives your server the speed and stability it needs.

What You Need Before Connecting

Before we start the integration process, here are the essential tools and setups you need:

  • MariaDB Server (installed locally or on your remote host)
  • FiveM Server Files (already running and tested)
  • MySQL Wrapper: either mysql-async or oxmysql (popular Lua libraries)
  • Access to your server.cfg file
  • Basic SQL knowledge (helpful, not mandatory)

Having these ready will ensure a smooth and error-free setup.

How to Connect MariaDB to Your FiveM Server

Step 1: Install MariaDB on Your Server

If you’re running a local development environment:

  • On Windows, download the installer from the official MariaDB website

On Ubuntu/Linux, use this command:
sudo apt update

  • sudo apt install mariadb-server

Make sure the MariaDB service is running:

sudo systemctl start mariadb

For remote hosts, follow your hosting provider’s documentation to enable and access MariaDB.

Step 2: Create a Database and User

Once MariaDB is installed, you need to create a database that FiveM can use:

CREATE DATABASE fivem_db;

CREATE USER ‘fivem_user’@’localhost’ IDENTIFIED BY ‘yourpassword’;

GRANT ALL PRIVILEGES ON fivem_db.* TO ‘fivem_user’@’localhost’;

FLUSH PRIVILEGES;

You can also do this via phpMyAdmin if you prefer a GUI over SQL commands.

Step 3: Install a MySQL Wrapper (mysql-async or oxmysql)

Head to GitHub or the FiveM forums to download your chosen MySQL wrapper.

  • mysql-async:
  • oxmysql (recommended for newer setups):

Place the wrapper folder inside your resources directory.

Add this line to your server.cfg to ensure it loads:

ensure oxmysql

Step 4: Configure Your server.cfg for MariaDB

Now it’s time to set up your database connection. Add the following line to your server.cfg:

set mysql_connection_string “server=127.0.0.1;database=fivem_db;userid=fivem_user;password=yourpassword”

Pro Tips:

  • Replace 127.0.0.1 with your actual database IP if it’s on a remote machine.
  • Ensure ports like 3306 are open in your firewall.
  • Double-check your username and password match the credentials you created.

Step 5: Set Up a Test Script

To verify everything works, create a basic Lua script that queries the database:

MySQL.ready(function()

    print(“Connected to MariaDB!”)

end)

Add the script to a resource and start it in your server.cfg. Launch your FiveM server and look for the success message in your console.

If you see the message, congrats — your FiveM server is now connected to MariaDB!

Common Issues and Fixes

Problem: Connection refused or timeout

  • Fix: Check firewall, IP address, and ensure MariaDB service is running.

Problem: Authentication error

  • Fix: Ensure credentials and user permissions are correct.

Problem: Resource not found

  • Fix: Make sure the ensure oxmysql line is correctly placed in server.cfg.

Problem: “No such module”

  • Fix: Ensure the wrapper is compatible with your server version.

Best Practices for Using MariaDB with FiveM

  • Always sanitize SQL inputs to prevent injection attacks.
  • Use indexes and primary keys for faster lookups.
  • Regularly back up your database.
  • Use structured data types and follow schema naming conventions.
  • Avoid hardcoding passwords in public/shared config files.

Advanced Tips

  • Use Docker: Host MariaDB in a container for isolated and reproducible environments.
  • Remote Connections: Use SSL to encrypt remote DB connections.
  • Async Queries: Use async SQL queries to reduce server lag during data-intensive tasks.

Conclusion

Now that you know how to connect MariaDB to your FiveM server, you’re ready to create a much more scalable and immersive experience. With proper setup and testing, your server will handle player data more efficiently and securely.

Whether you’re running a small RP server or building the next big thing in FiveM, this guide puts the power of structured databases in your hands. Go ahead, implement MariaDB, and watch your server thrive!

FAQs

Is MariaDB better than MySQL for FiveM?

Yes, MariaDB is a compatible fork of MySQL and often performs faster, especially for FiveM setups.

Can I use MariaDB on a remote host?

Absolutely. Just make sure the IP is accessible and the correct port is open (usually 3306).

Which library is more popular: mysql-async or oxmysql?

Oxmysql is newer and better maintained. It supports newer FiveM frameworks and has async support.

Is it safe to store sensitive RP data in MariaDB?

Yes, as long as you secure your database with proper credentials, limited permissions, and regular backups.

Can I migrate from flat files to MariaDB?

Yes. You’ll need to convert existing data into SQL insert statements or import it manually.

RELATED ARTICLES

Latest News