Skip to content
imshooter edited this page Dec 1, 2026 · 2 revisions

Note

mysql is experimental and already runs in production. Its natives may still change from one version to the next. It was made with Claude Opus 5.5, a model by Anthropic.

mysql is a MySQL and MariaDB plugin for open.mp and SA-MP. The same binary loads as an open.mp component or as a legacy plugin. Its natives keep the names SA-MP scripts have long used for MySQL, as mysql_tquery and cache_get_value_name_int, and they come again with open.mp names in full words, as MySQL_ThreadedQuery and Cache_GetValueNameInt, in the same include.

Every connection runs on a thread of its own, and a finished query calls its public on the next server tick, so the game never waits for the database. The plugin formats and escapes queries, prepares statements and sends their rows in bulk, runs transactions, maps rows to variables, reads JSON cells, and hashes passwords with Argon2id or bcrypt off the game thread.

This wiki describes version 0.6.0.

Guides

  • Installation: the files of a release and the first start.
  • Configuration: the options of a connection, in a script or in mysql.ini.
  • Queries: queries in order, in parallel, waited for, built in pieces and read from files.
  • The cache: reading rows and cells, result sets and saved caches.
  • JSON cells: reading JSON columns by key or pointer.
  • Prepared statements: statements and batches.
  • Transactions: queries and statements that apply all together or not at all.
  • The ORM: a row of a table mapped to variables.
  • Passwords: hashing and verifying with Argon2id and bcrypt.
  • Errors: failed queries, lost connections and limits.
  • TLS: encrypted connections and how the server is verified.
  • Coming from another plugin: what to change, and what may differ.
  • Performance: what each kind of work costs.

Reference

  • Functions: every native and the callback, by subject.
  • Specifiers: what each % writes into a query or binds in a statement.
  • Callback formats: the letters that pass values to a public.

A first script

Reads the score of a player when they connect.

new MySQL:gDatabase;

forward OnScoreRead(playerid);

public OnGameModeInit() {
    gDatabase = mysql_connect_file();

    return 1;
}

public OnPlayerConnect(playerid) {
    new
        name[MAX_PLAYER_NAME + 1]
    ;

    GetPlayerName(playerid, name, sizeof (name));
    mysql_tquery_format(gDatabase, "SELECT score FROM players WHERE name = %q", "OnScoreRead", "i", playerid, name);

    return 1;
}

public OnScoreRead(playerid) {
    new
        score
    ;

    if (cache_get_value_name_int(0, "score", score)) {
        SetPlayerScore(playerid, score);
    }

    return 1;
}

Home

Guides

Reference

Functions

Connections
Queries
Cache
JSON cells
ORM
Queries built in pieces
Prepared statements
Batches
Transactions
Passwords
Callbacks

Clone this wiki locally