oxmysql / mysql-async: Database connection failed (FiveM)
oxmysql and mysql-async are the two main MySQL libraries FiveM resources use. When they log 'Database connection failed' or 'ECONNREFUSED', FXServer started but couldn't reach the MySQL server. Every resource that runs queries fails silently or throws Lua errors after this. The fix is always in the connection configuration — MySQL address, credentials, or firewall.
Fastest path: paste your crash report into the Crash Doctor — it identifies this pattern and 40+ others automatically. No signup.
How to fix it
- 1
Check the connection string in server.cfg
oxmysql uses: set mysql_connection_string "mysql://user:password@host/dbname". mysql-async uses: set mysql_connection_string "server=host;database=dbname;userid=user;password=pass". Verify user, password, host, and database name are all correct — a single wrong character causes the failure.
- 2
Verify MySQL is running on the database server
SSH into the database server and run 'systemctl status mysql' or 'systemctl status mariadb'. If it's stopped, start it. If it's crashing, check /var/log/mysql/error.log. A crashed MySQL means no amount of connection string fixes will help.
- 3
Test connectivity from the FiveM server
From the FXServer machine, run: 'mysql -h <host> -u <user> -p<password> <dbname>'. If this fails, the problem is network connectivity or MySQL config, not the FiveM resource. Check firewall rules — MySQL's default port 3306 must be open from the FXServer IP to the database IP.
- 4
Allow the FiveM server's IP in MySQL bind-address and user grants
MySQL's /etc/mysql/mysql.conf.d/mysqld.cnf may have bind-address = 127.0.0.1, which blocks all remote connections. Change to 0.0.0.0 (then restrict via firewall). Also run: GRANT ALL ON dbname.* TO 'user'@'fivem_server_ip' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; in the MySQL console.
Alternative causes
These can produce the same error message — worth ruling out if the steps above don't resolve it.
Wrong hostname when MySQL is on the same machine
If MySQL runs on the same VPS as FXServer, use '127.0.0.1', not 'localhost'. MySQL on Linux distinguishes between them: 'localhost' triggers a Unix socket connection, which may not be accessible from inside the FXServer process path. '127.0.0.1' forces TCP and works in both cases.
MySQL user doesn't have privileges on the database
Even if the TCP connection succeeds, a user without SELECT/INSERT/UPDATE/DELETE on the database gets 'Access denied'. Check grants: 'SHOW GRANTS FOR user@host;' in MySQL console.
Frequently asked
Do I need MySQL for every FiveM server?
Only if you run resources that require it (ESX, QBCore, and most roleplay resources need a database). A vanilla FXServer with simple gamemodes doesn't need MySQL at all.
What's the difference between oxmysql and mysql-async?
oxmysql is the modern replacement for mysql-async, offering better performance and a cleaner API. They use a similar connection string format. If you're starting fresh, use oxmysql. If you have legacy resources written for mysql-async, they usually work with oxmysql's compatibility shim.
Can I use MySQL on a different server from FiveM?
Yes — many setups use a separate database VPS. Use the database server's public or private IP in the connection string. Private IPs are preferred if both servers are on the same network (same datacenter VLAN) for latency and security.
Want this auto-fixed on your server?
CoalHosting's Minecraft hosting runs the same pattern database against every crash and applies the known fix before your players notice. Free crash diagnosis works on any server, hosted or not.
Related crashes
Resource dependency failed to start (FiveM)
Fix FiveM 'resource X has a dependency on Y which failed to start' — install the missing dependency and ensure…
License key was not accepted (FiveM / FXServer)
Fix the FiveM 'license key was not accepted' error — your sv_licenseKey in server.cfg is invalid, expired, or …
FXServer crash loop (server keeps restarting)
Fix a FiveM FXServer crash loop — the server restarts immediately after starting. Read the last log, find the …
Last reviewed 2026-06-15. If a step is wrong or out of date, tell us — we'll fix the article and the auto-pattern at the same time.