Almost every FiveM server stores data in a database through oxmysql, so when the database connection fails, huge parts of your server break โ players don't load, items don't save, jobs don't persist. Here's how to fix it.
What oxmysql does
oxmysql is the bridge between your FiveM server and your MySQL/MariaDB database. Your framework and many scripts use it to read and write data. If oxmysql can't connect, anything that touches the database fails.
Cause 1: Wrong connection string
The most common cause by far. Your mysql_connection_string in server.cfg must exactly match your database's details.
Fix: Check the connection string format. A typical one looks like:
set mysql_connection_string "mysql://username:password@localhost:3306/databasename"Verify every part:
- username and password โ correct database credentials
- localhost โ or your database host address
- 3306 โ the MySQL port (default 3306)
- databasename โ the exact name of your database
A single wrong character here breaks everything. Watch the console โ oxmysql usually prints a clear connection error telling you what failed.
Cause 2: Database server not running
oxmysql can't connect to a database that isn't running.
Fix: Make sure your MySQL/MariaDB server is actually started. If you're self-hosting with something like XAMPP or a standalone MariaDB, confirm the service is running. On a managed host, check their database panel.
Cause 3: Database doesn't exist
If the database named in your connection string hasn't been created, connection fails.
Fix: Create the database (via phpMyAdmin, HeidiSQL, or your host's panel), and make sure its name matches the connection string exactly.
Cause 4: Wrong credentials or permissions
If the username/password is wrong, or that user lacks permission for the database, you'll get an access-denied error.
Fix: Verify the credentials work by logging into your database tool with them. Make sure the user has full permissions on the target database.
Cause 5: Wrong host or port
If your database runs somewhere other than localhost:3306, the string must reflect that.
Fix: Set the correct host address and port. Remote databases need the right IP and an open port; managed hosts provide these details.
Cause 6: oxmysql not loading first
oxmysql must start before anything that uses it.
Fix: In server.cfg, ensure oxmysql should come very early โ before your framework and any resource that queries the database.
The fix checklist
- Read the oxmysql console error โ it usually states the exact problem.
- Verify the connection string piece by piece (user, password, host, port, database name).
- Confirm the database server is running.
- Confirm the database exists with the right name.
- Test credentials in a database tool.
- Ensure oxmysql loads first in server.cfg.
Work through these and the connection will come up โ it's always one of these.
Clean database usage matters
Scripts that hammer the database or use it inefficiently cause hidden lag even once connected. Well-built resources use oxmysql efficiently. At Viper Development, our scripts handle data cleanly and document their database needs. Browse our scripts โ.