FiveM Database Errors: Fixing oxmysql Connection Problems
ESX and QBCore store players, vehicles, items and jobs in a MySQL or MariaDB database. FiveM servers usually connect to it through the oxmysql resource. If the database is wrong, you will see errors on startup or players will lose data.
How the connection works
oxmysql reads a connection string from server.cfg. It looks like this pattern, with your own details in place of the placeholders:
- set mysql_connection_string "mysql://user:password@host/databasename"
The details come from your database provider or panel. Keep the line above the point where oxmysql and your framework are ensured.
Common errors and fixes
- Access denied for user: the username or password is wrong. Re-copy them and check for special characters in the password. If the password contains characters like @ or #, it may need to be URL encoded in the string.
- Unknown database: the database name is wrong or the database was never created.
- Connection refused or timeout: the host or port is wrong, or the database does not allow connections from your game server. Check the host address you were given.
- Table does not exist: you did not import the framework SQL file. Import the SQL that ships with ESX or QBCore, plus the SQL file for each script that needs its own tables.
Importing SQL files
- Open your database tool, such as phpMyAdmin if provided.
- Select your database.
- Use Import and pick the .sql file from the script.
- Check that tables appear, then restart the server.
Tips
- Import each script SQL file only once; running it twice may fail or create duplicates.
- Ensure oxmysql before the framework and any resource that queries the database.
- Do not share your connection string in public screenshots.
- Make regular database backups before big updates.
Older servers may still use the legacy mysql-async resource. Do not run two database resources that provide the same connection at once. If you are unsure which resource your scripts expect, check their documentation.