Install MariaDB for FiveM and connect it with oxmysql
Install MariaDB on Linux, create a limited database user, and set mysql_connection_string for oxmysql in server.cfg, with a connection check.
Short answer
Use MariaDB. The oxmysql documentation recommends MariaDB for compatibility and performance, and says oxmysql also has improved compatibility with MySQL 8. On Ubuntu or Debian, install mariadb-server from the official MariaDB repository, create one database and one user for your server, then set mysql_connection_string in server.cfg with set.
Why FiveM needs a database
Most frameworks and many scripts store persistent data in a SQL database: player accounts, characters, inventories, vehicles and job data. oxmysql is the resource that gives your other scripts a way to run those queries. If oxmysql cannot connect, scripts that depend on it will fail on start or when they read or write data.
Install MariaDB on Linux (Ubuntu or Debian)
The commands below come from the official MariaDB page for installing .deb packages. That page lists Debian 11, 12 and 13, and Ubuntu 22.04 and 24.04.
- Add the official MariaDB repository. The setup script is downloaded and run with
bash, so read it first if you want to check what it does:
``bash curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash ``
- Update the package list:
``bash sudo apt update ``
- Install the server:
``bash sudo apt-get install mariadb-server ``
- Harden the installation. The MariaDB docs describe this script as able to set a root password, remove anonymous users, disallow remote root login and remove the test database. Answer its prompts:
``bash mariadb-secure-installation ``
Other distributions are not covered here. Use the official MariaDB install page for your OS.
Windows
Windows servers also need MariaDB or MySQL running and reachable on port 3306. This post does not include tested Windows installer steps. Install MariaDB from the official MariaDB documentation, then use the same database, user and mysql_connection_string steps below. The Windows-specific install is not confirmed in this post.
Create a database and a limited user
Give your server its own database and a user that can only use that database. Do not use the MariaDB root account in your FiveM config. The SQL below is a template. Replace every placeholder with your own values and choose a long, unique password. Never paste a real password into a blog post, forum post or screenshot.
CREATE DATABASE <database_name> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER '<db_user>'@'localhost' IDENTIFIED BY '<strong_password>';
GRANT ALL PRIVILEGES ON <database_name>.* TO '<db_user>'@'localhost';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON <database_name>.* limits the user to one database. Do not grant it on *.*.
Set the oxmysql connection string
The convar is mysql_connection_string. The oxmysql documentation gives two formats: a URI form and a semicolon key/value form. Use one of them in server.cfg, before ensure oxmysql:
set mysql_connection_string "mysql://<db_user>:<url_encoded_password>@127.0.0.1:3306/<database_name>"
set mysql_connection_string "user=<db_user>;password=<password>;host=127.0.0.1;port=3306;database=<database_name>"
Use set, not setr. The oxmysql docs say: "Make sure you only ever use set." In the URI form, percent-encode special characters in the password. In the key/value form, a semicolon in the password will break the value. Use 127.0.0.1 when the database runs on the same machine. The oxmysql docs example uses localhost.
Then make sure ensure oxmysql runs before any resource that uses the database.
Test the connection
Start the server and watch the console during startup for oxmysql messages. If the connection fails, the error text tells you which problem you have; the ECONNREFUSED guide covers the most common one. Before you blame oxmysql, log in to MariaDB with the new user and confirm that it can see <database_name>. If that login fails, fix the user or password first.
Common errors
- ECONNREFUSED 127.0.0.1:3306: nothing is listening on port 3306. MariaDB is not installed, not running, or running on another host. See oxmysql ECONNREFUSED 3306.
- Access denied for user: the user, password or host in the string does not match a MariaDB account. Check the
@'localhost'part of the user you created. - Old connection string still in use: a later
set mysql_connection_stringline may override yours, or the line sits afterensure oxmysql. Check the order inserver.cfg.
Frequently asked questions
Can I use MySQL instead of MariaDB?
Yes, according to the oxmysql docs. The docs say oxmysql has improved compatibility with MySQL 8, and they recommend MariaDB for compatibility and performance. This post did not test MySQL.
Should I use localhost or 127.0.0.1?
Use 127.0.0.1 when you want to force the IPv4 address. The oxmysql docs show localhost in their example. Either can work if MariaDB listens where oxmysql connects.
Why do I still see a 127.0.0.1 error after changing the string?
Check that the set mysql_connection_string line is in server.cfg, uses set, and is not overridden later. If the error still shows the old host, the value oxmysql reads is not the one you edited.
Sources
- oxmysql documentation (Overextended):
mysql_connection_string, the URI and key/value formats,setguidance, MariaDB and MySQL 8 notes. - oxmysql on GitHub: project repository. Its README points to the documentation above.
- Installing MariaDB .deb files (MariaDB docs): repository setup script,
aptcommands and supported OS versions. - mariadb-secure-installation (MariaDB Knowledge Base): what the hardening script does.
Last checked: 29 November 2026
Not confirmed: Windows install steps; the exact MariaDB version that oxmysql requires (the docs state no minimum); the SQL template and the note on percent-encoding were not taken from a source page and follow standard SQL and URI rules; service start and client login commands are not shown because no fetched source gave them.
FiveM.tools was founded with sponsorship from Nyru.