Skip to content

Configuration

imshooter edited this page Nov 29, 2026 · 1 revision

A connection is opened with mysql_connect, which takes a set of options from mysql_init_options, or with mysql_connect_file, which reads mysql.ini.

new MySQL:gDatabase;

public OnGameModeInit() {
    new const
        MySQLOpt:options = mysql_init_options()
    ;

    mysql_set_option(options, SERVER_PORT, 3306);
    mysql_set_option(options, POOL_SIZE, 4);
    mysql_set_option(options, SLOW_QUERY, 50);
    gDatabase = mysql_connect("127.0.0.1", "game", "secret", "game", options);

    if (mysql_errno(gDatabase) != 0) {
        print("The database is not there yet. Queries will connect when it is.");
    }

    return 1;
}

Options

Option In mysql.ini Value Default
SERVER_PORT server_port port of the server 3306
CHARSET charset character set of the text latin1
MULTI_STATEMENTS multi_statements several statements in one query false
POOL_SIZE pool_size connections for parallel queries, 0 to 32 4
AUTO_RECONNECT auto_reconnect always on true
ERROR_CALLBACK error_callback call the public of a failed query too false
CONNECT_TIMEOUT connect_timeout seconds to connect 5
READ_TIMEOUT read_timeout seconds to wait for an answer none
WRITE_TIMEOUT write_timeout seconds to send a query none
SLOW_QUERY slow_query milliseconds from which a query is logged none
MAX_QUERY_LENGTH max_query_length bytes a query may have none
MAX_PENDING max_pending queries waiting or running none
MAX_QUERIES_PER_SECOND max_queries_per_second queries sent in a second none

The options of TLS are on the TLS page. A query past a limit is refused: it is not sent, the native returns false, and a line is logged at most once a second.

mysql.ini

mysql_connect_file looks for a relative path in scriptfiles first, then in the folder of the server. A line is key = value, with hostname, username, password, database and the keys above. Lines that start with #, ; or [ are skipped. ${NAME} in a value is replaced by the environment variable NAME, and a variable that is not set makes the file invalid.

hostname = 127.0.0.1
username = game
password = ${MYSQL_PASSWORD}
database = game
pool_size = 4

Plugin options

mysql_global_options sets what holds for every handle. DUPLICATE_CONNECTIONS lets a second mysql_connect with the same server, account and database open another handle, where by default it gives the handle open already. mysql_log chooses what is logged.

Home

Guides

Reference

Functions

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

Clone this wiki locally