Frameworks & scripts

oxmysql

Also called MySQL connector

The standard database connector resource for FiveM, letting Lua and JavaScript resources query MySQL or MariaDB asynchronously.

oxmysql is the resource most FiveM servers use to talk to their database. It replaced older connectors like mysql-async and ghmattimysql, and it offers compatible exports so scripts written for those still run in most cases.

Configuration is a single convar in server.cfg:

set mysql_connection_string "mysql://user:password@localhost/dbname?charset=utf8mb4"

It must be started before any resource that queries the database, which in practice means directly after the base resources and before the framework. Resources use it through the MySQL object, for example MySQL.query, MySQL.single, MySQL.insert and MySQL.update, with both callback and await styles.

A few operational points matter more than the API:

  • Parameterise every query. Building SQL by concatenating player input is how servers get their database wiped. oxmysql supports placeholders; use them.
  • Watch slow query warnings. oxmysql logs queries that take too long. A handful of slow queries on a busy table is usually a missing index, not a hardware problem.
  • Keep credentials out of shared files. The connection string contains the database password. Treat it like the licence key.

oxmysql works with both MySQL and MariaDB. Most FiveM hosts and local setups use MariaDB, and connection errors after a fresh install are more often a wrong password, user host or authentication plugin than a bug in the connector.

Related terms

Trying to get your server seen?

The live leaderboard shows what the numbers look like at the top of the list, and the upvote calculator turns a target server into a campaign size. The full glossary is here.