oxmysql for FiveM: what it is, common mistakes and the AI skill

View on skills.sh

Updated

Don’t want to manage skills yourself? Get the full app.

oxmysql is the MySQL and MariaDB driver most FiveM servers use. You call MySQL.query, insert, prepare, single and transaction with placeholders instead of string concatenation. This guide covers setup, mistakes that break scripts and the AI skill.

oxmysql is the database library for FiveM that replaced mysql-async and ghmattimysql. It runs on the server only, talks to MySQL or MariaDB, and exposes a small Lua API under the MySQL global. If your resource stores anything (player data, vehicles, inventories, logs), this is the layer you write against. The SKILL.md recommends MariaDB over MySQL 8 for compatibility.

Quick reference

In Lua, add .await to get the result inline, or pass a callback as the last argument. Parameters always go through ? placeholders.

Call Returns
MySQL.query.await(sql, params) Rows for a SELECT, otherwise insertId or affectedRows
MySQL.single.await(sql, params) One row, or nil
MySQL.scalar.await(sql, params) One value from one column of one row
MySQL.insert.await(sql, params) The new insert id
MySQL.update.await(sql, params) The affected row count
MySQL.prepare.await(sql, params) Prepared statement, ? placeholders only
MySQL.transaction.await(queries) Several queries that succeed or fail together

Manifest line, above your other server scripts: server_script '@oxmysql/lib/MySQL.lua'. Server side only.

What oxmysql gives you

Setup is one line in fxmanifest.lua, placed above your other server scripts: server_script '@oxmysql/lib/MySQL.lua'. After that, the MySQL table is available in every server script of the resource.

  • MySQL.query and MySQL.query.await: run any statement. A SELECT returns rows, other statements return insertId or affectedRows.
  • MySQL.insert: insert a row and get the new insert id back.
  • MySQL.update: update rows and get the affected count.
  • MySQL.single: one row or nil, the right call for "load this player".
  • MySQL.scalar: one value from one row and one column, for counts and balances.
  • MySQL.prepare: prepared statements with ? placeholders only, faster when you run the same query many times.
  • MySQL.rawExecute: raw execution with no automatic result shape.
  • MySQL.transaction: several queries that succeed or fail together.

Every function takes parameters through ? placeholders. Values never go into the SQL string. The reference is at coxdocs.dev/oxmysql.

Common mistakes with oxmysql

  • Using the mysql-async API. MySQL.Sync.fetchAll and MySQL.Async.execute come from a library that is no longer maintained. In new code they either fail or depend on a compatibility layer you do not control. Use MySQL.query.await, MySQL.insert and the rest of the oxmysql API.
  • Calling MySQL from a client script. The library is server only. A client has no database access and no MySQL global. Put the query in a server script and hand the result to the client through an event or a callback.
  • Concatenating values into SQL. 'SELECT * FROM users WHERE identifier = "' .. identifier .. '"' is an injection waiting to happen. Write MySQL.single.await('SELECT * FROM users WHERE identifier = ?', { identifier }).
  • Awaiting one query per row in a loop. Saving 300 vehicles with MySQL.update.await inside a for loop means 300 round trips. Batch the work into one statement where you can, or wrap the set in MySQL.transaction.
  • Forgetting the lib line in the manifest. The symptom is "attempt to index a nil value (global 'MySQL')" on the first query. Add server_script '@oxmysql/lib/MySQL.lua' before your other server scripts.

Why AI assistants get oxmysql wrong

Generic assistants have read a decade of FiveM scripts, and most of that code uses mysql-async. Ask for "save the player's money" and you get MySQL.Async.execute with the value concatenated into the string, sometimes inside a client file. It runs nowhere, or worse, it runs and leaves the server open to injection.

The oxmysql skill gives the assistant one rule file per function: placeholders.md, query.md, insert.md, prepare.md, update.md, single.md, scalar.md, rawExecute.md and transaction.md. Each one states what the function returns and how parameters are passed. The assistant reads the rule that matches your request and writes code that uses the real API on the right side of the network.

To see how a skill compares with other FiveM AI setups, read our comparison.

Install the oxmysql skill in 30 seconds

  1. Click "Download SKILL.md" at the top of this page.
  2. Unzip it into the skills or rules folder of your AI tool. The install section below shows the exact path for Claude Code, Cursor and VS Code.
  3. Ask the assistant for something concrete, like "load a player's bank balance by identifier", and check that it uses MySQL.scalar.await with a ? placeholder in a server script.

How to install this skill

Download the zip, unzip it, and place the folder where your tool loads skills or rules. The exact path depends on the tool:

Claude Code

Unzip into .claude/skills/oxmysql/ inside the project (the folder must contain SKILL.md). For every project, use ~/.claude/skills/oxmysql/ instead.

Claude Code skills docs

Cursor

Cursor loads project rules from .cursor/rules/. Add a rule file there that points to the unzipped skill, or paste the contents of SKILL.md and the rule files into a rule. The format is .mdc with frontmatter and changes between versions, so check the docs for your version.

Cursor rules docs

VS Code / Copilot

Copilot reads instruction files from .github/instructions/*.instructions.md. Copy SKILL.md there with an applyTo glob for your Lua files, and keep the rule files next to it.

VS Code custom instructions docs

The SKILL.md file

This is the file your AI assistant reads. It links to the rule files bundled in the download.

Skill contents (includes SKILL.md and any other files)

OxMySQL

SQL integration for FiveM using OxMySQL (replacement for mysql-async / ghmattimysql). Server-side only. Use MariaDB over MySQL 8 for compatibility.

When to use

  • User asks for database queries, inserts, updates, or SQL in a FiveM resource.
  • Editing or writing code that uses MySQL.* or exports.oxmysql.
  • Designing tables, upserts, or transactions.

Setup

  • Lua: server_script '@oxmysql/lib/MySQL.lua' in fxmanifest (above other scripts).

Rules

Read the rule that matches what you're doing:

  • rules/placeholders.md — Safe parameters (? placeholders), avoid SQL injection.
  • rules/query.md — MySQL.query / MySQL.query.await: SELECT returns rows; other statements return insertId/affectedRows.
  • rules/insert.md — MySQL.insert: insert row, returns insert id.
  • rules/prepare.md — MySQL.prepare: prepared statements, only ? placeholders; faster for repeated queries.
  • rules/update.md — MySQL.update: update rows, returns affected count.
  • rules/single.md — MySQL.single: one row or nil.
  • rules/scalar.md — MySQL.scalar: single value (one row, one column).
  • rules/rawExecute.md — MySQL.rawExecute: raw execution, no automatic result shape.
  • rules/transaction.md — MySQL.transaction: run multiple queries in a transaction.

References (look up if not covered in the rules above)

If something isn't covered in the rules above, check the official docs:

Frequently asked questions

Is oxmysql free?
Yes. oxmysql is open source, maintained by the Overextended and CommunityOx teams, and published on GitHub. You can run it on any server at no cost.
Does oxmysql work with ESX and QBCore?
Yes. Current ESX Legacy and QBCore builds ship with oxmysql as their database layer, so any script you write for those frameworks can use MySQL.query, MySQL.insert and the rest of the API.
Can I use this skill with ChatGPT?
Yes, with a manual step. The SKILL.md is plain markdown, so you can paste it into the conversation as context. Native skill support is for Claude Code, Cursor and VS Code.

Longer reads from the FiveAI blog on the same topic.

More skills