Repository navigation
Home
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 an open.mp component for MySQL and MariaDB. 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 component formats and escapes queries, prepares statements and sends their rows in bulk, reads JSON cells without a parser in Pawn, and hashes passwords with Argon2id or bcrypt off the game thread.
This wiki describes version 0.2.0.
- Installation: the files of a release and the first start.
-
Configuration: the settings of a connection, in a script or in
mysql.ini. - Queries: sending queries in order, in parallel or waiting for them, and building long ones in pieces.
- Results: reading rows, cells and result sets, and keeping a result for later.
- JSON cells: reading JSON columns by key or pointer.
- Prepared statements: statements, batches and when each pays off.
- 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 R41: the native that replaces each function of the R41 plugin.
- Performance: what each kind of work costs.
- Functions: every native and the callback, by subject.
-
Specifiers: what each
%writes into a query or binds in a statement. -
JSON types: the values of
MYSQL_JSON.
Reads the score of a player when they connect.
new MySQL:gDatabase;
forward OnScoreRead(playerid);
public OnGameModeInit() {
gDatabase = MySQL_ConnectFile("mysql.ini");
return 1;
}
public OnPlayerConnect(playerid) {
new
name[MAX_PLAYER_NAME + 1]
;
GetPlayerName(playerid, name, sizeof (name));
MySQL_Query(gDatabase, "OnScoreRead", playerid, "SELECT score FROM players WHERE name = %q", name);
return 1;
}
public OnScoreRead(playerid) {
if (MySQL_GetRowCount() != 0) {
SetPlayerScore(playerid, MySQL_GetInt(0, "score"));
}
return 1;
}The query is formatted by the component, %q escapes the name and puts it between quotes, and OnScoreRead receives the playerid it was sent with. Inside it, the MySQL_Get natives read the result of that query.
MySQL 0.2.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- Results
- JSON cells
- Prepared statements
- Passwords
- Errors
- TLS
- Coming from R41
- Performance
Reference
Functions