Fix oxmysql "connect ECONNREFUSED 127.0.0.1:3306" in FiveM
oxmysql cannot reach your database: ECONNREFUSED 127.0.0.1:3306 means nothing is listening. Check MariaDB, the connection string and load order.
[ script:oxmysql] Unable to establish a connection to the database (ECONNREFUSED)!
[ script:oxmysql] Error -4078: connect ECONNREFUSED 127.0.0.1:3306
ECONNREFUSED 127.0.0.1:3306 means oxmysql tried to open a connection to a database on this machine, port 3306, and nothing answered on that port. In most cases MariaDB is not installed, not running, or running somewhere else than your mysql_connection_string says. It is almost never a problem with oxmysql itself or with your scripts.
The number after "Error" depends on the OS: Windows reports -4078, Linux -111. The meaning is the same.
Last checked: 5 October 2026
What does ECONNREFUSED 127.0.0.1:3306 mean?
ECONNREFUSED is a network error from Node.js, which oxmysql runs on. The operating system answered "connection refused" because no program was listening on the address and port. Three parts of the message matter:
- 127.0.0.1 is this machine (localhost). oxmysql is looking for the database on the same computer or container as FXServer.
- 3306 is the default MySQL/MariaDB port.
- Refused, not "timed out", means the machine was reached but no database is listening there. A firewall usually causes a timeout instead.
If the error shows ::1:3306 instead, localhost was resolved to the IPv6 address and your database only listens on IPv4. Use 127.0.0.1 instead of localhost in the connection string.
One more detail from the oxmysql source: if the mysql_connection_string convar is empty when oxmysql starts, it falls back to mysql://root@localhost. So if your connection string points to another host but the error still says 127.0.0.1:3306, oxmysql is not reading your string at all. See the load order section below.
Quick triage
| Situation | Most likely cause |
|---|---|
| New local setup on Windows | MariaDB was never installed, or the service is stopped |
| Worked yesterday, fails today | MariaDB service stopped or crashed (disk full, update, reboot) |
| Moved from a home PC to a host | The string still says localhost, but the database is on another server |
| Game panel or Docker (Pterodactyl and similar) | localhost points to the container, not the database host |
| Your string has a remote IP, error says 127.0.0.1 | The convar is not set before oxmysql starts, or has a typo |
| Error is "Access denied" instead | The database is up; user or password is wrong (see below) |
Step 1: make sure MariaDB is installed and running
The oxmysql documentation recommends MariaDB and says not to set up XAMPP just to run your database, because XAMPP is a web development stack. Install MariaDB directly from mariadb.org or your Linux package manager.
On Windows:
- Press Win+R, type
services.mscand press Enter. - Find the MariaDB (or MySQL) service. If it is missing, MariaDB is not installed.
- If its status is not "Running", right-click it and choose Start. Set the startup type to Automatic so it survives reboots.
- Check that something listens on 3306:
netstat -ano | findstr :3306
On Linux (Debian/Ubuntu):
- Check the service:
sudo systemctl status mariadb - Start it and enable it on boot:
sudo systemctl enable --now mariadb - Check the port:
sudo ss -ltnp | grep 3306
If the service refuses to start, read its log (Windows Event Viewer, or sudo journalctl -u mariadb on Linux). A full disk and a crashed table are common reasons.
Then test the login yourself with the MariaDB client, using the same user, password and database as in your config:
mysql -u root -p -h 127.0.0.1 -P 3306 fivem
If this works, the database is fine and the problem is in your FiveM config.
Step 2: check the connection string
oxmysql reads the mysql_connection_string convar. The official docs show two formats; both use set:
set mysql_connection_string "mysql://root:12345@localhost:3306/fivem"
set mysql_connection_string "user=root;password=12345;host=localhost;port=3306;database=fivem"
Check every part:
- host:
localhostor127.0.0.1only if the database runs on the same machine (and the same container) as FXServer. Otherwise the database server's IP or hostname. - port: 3306 unless you changed it. Some hosts give you a different port.
- user and password: the database user, not your Windows or panel login.
- database: the name of the database that holds your framework's tables (for example
fivem). It must exist.
Reserved characters in the password
The oxmysql docs warn that these characters cause problems in connection strings: ; , / ? : @ & = + $ #. In the URI format, an @ or : in the password breaks how the string is split, so oxmysql ends up with a wrong host or user. The docs say to avoid these characters or switch to the other format.
The simplest fix is to give the database user a password with only letters and numbers (make it long instead). Keep in mind that the semicolon format splits on ;, so a password containing ; breaks that format too.
Step 3: check the load order
The oxmysql docs say to put start oxmysql at the top of your resource list and to set the connection string before any other resources start. A working server.cfg order looks like this:
set mysql_connection_string "mysql://fivem:LongPassword123@127.0.0.1:3306/fivem"
ensure oxmysql
ensure ox_lib
# framework and other resources after this
Common mistakes:
- the
set mysql_connection_stringline comes afterensure oxmysql, or is in a separate.cfgfile that is executed later or not at all, - a typo in the convar name, such as
mysql_connectionstring, - two
set mysql_connection_stringlines, where the wrong one wins, - a txAdmin recipe wrote the string into one
server.cfgwhile the server is started with another.
Hosted servers, panels and remote databases
When the server runs in a container (Pterodactyl and similar game panels use Docker), localhost means the container itself, and there is no database inside it. Use the database host and port your panel shows. Pterodactyl, for example, lists them in the Databases tab of your server.
When the database runs on another machine:
- MariaDB must listen on a reachable address. On Debian/Ubuntu the
bind-addresssetting lives in/etc/mysql/mariadb.conf.d/50-server.cnf; the default of127.0.0.1only accepts local connections. - The database user must be allowed from the game server's IP, not only from
localhost. - The firewall on the database machine must allow port 3306 only from your game server's IP. Do not open 3306 to the whole internet.
A firewall in the way usually gives ETIMEDOUT, not ECONNREFUSED. If you see a timeout, look at the firewall first.
"Access denied for user 'root'@'localhost'"
Error 1045: Access denied for user 'root'@'localhost' (using password: YES)
This is a different error, and good news: the database is running and reachable. It rejected the login. Causes:
- wrong password in the connection string,
- the user does not exist for that host (
'root'@'localhost'and'root'@'%'are different accounts in MariaDB), - on many Linux installs, MariaDB's root account uses socket authentication and does not accept a password from applications.
The clean fix is a dedicated user for FiveM. Run this in the MariaDB client as an admin, with your own password:
CREATE DATABASE IF NOT EXISTS fivem;
CREATE USER 'fivem'@'localhost' IDENTIFIED BY 'LongPassword123';
GRANT ALL PRIVILEGES ON fivem.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;
Then use fivem / LongPassword123 in the connection string. If FXServer connects from another machine, replace localhost with the game server's IP.
What usually doesn't help
Community-reported, from forum threads:
- Reinstalling oxmysql or switching to an older version. The resource is not the problem when the port refuses.
- Changing
ensureorder of your framework while MariaDB is not running. - Running XAMPP's MySQL "just for FiveM". The oxmysql docs advise against it.
- Disabling the Windows firewall for a local database. Local connections are not blocked by it.
If nothing works
Post in the Server Support category on forum.cfx.re, or in the Overextended community, with:
- the full oxmysql error lines from the console,
- your
mysql_connection_stringline with the password replaced by***, - the order of
setandensurelines inserver.cfg, - the database software and version (MariaDB or MySQL),
- where the database runs (same PC, same VPS, container, separate server),
- the result of the
mysql -u ... -h 127.0.0.1login test.
Never post your real database password.
Frequently asked questions
How do I fix connect ECONNREFUSED 127.0.0.1:3306 in FiveM?
Start (or install) MariaDB, check that it listens on port 3306, and make sure mysql_connection_string points to the right host and port. Put the set mysql_connection_string line before ensure oxmysql in server.cfg.
What is the correct oxmysql connection string?
The official formats are set mysql_connection_string "mysql://root:12345@localhost:3306/fivem" or set mysql_connection_string "user=root;password=12345;host=localhost;port=3306;database=fivem". Replace the user, password, host and database with your own.
Why does oxmysql still connect to 127.0.0.1 when I set another host?
oxmysql falls back to mysql://root@localhost when the convar is empty at startup. Your set line is probably after ensure oxmysql, in a config file that is not executed, or misspelled.
Can I use XAMPP for FiveM?
The oxmysql docs say not to set up XAMPP just to run your database and recommend installing MariaDB directly.
What does Access denied for user root localhost mean in oxmysql?
The database is running but rejected the login. Check the password, or create a dedicated FiveM user with its own password and rights on your database.
Should I open port 3306 in my firewall?
Only if the database is on a different machine than FXServer, and then only for your game server's IP. A local database needs no open port.
FiveM.tools was founded with sponsorship from Nyru.