ai-mysql
The database engine for third-party scripts. Stands in for oxmysql, mysql-async and ghmattimysql.
ai-mysql connects third-party scripts to your database. It answers oxmysql's exports and its @oxmysql/lib/MySQL.lua file, plus the older mysql-async and ghmattimysql names, so scripts written for any of them run unchanged.
ai-* scripts do not go through ai-mysql: each one runs AI Core's database engine (@aicore-fivem/mysql) inside itself, with its own small connection pool. ai-mysql is the same engine, shared by every third-party script.
What it does
- oxmysql for other scripts.
exports.oxmysql:query(...),MySQL.query.await(...)and every other oxmysql call works. - Old APIs. The export names of mysql-async (
mysql_fetch_all,mysql_execute...) and ghmattimysql (execute,scalar...) answer too. - Version check. Scripts that read oxmysql's version see 2.14.3, the oxmysql version ai-mysql follows, so they take their modern code path.
- Warnings for slow queries and very large results in the server console, like oxmysql.
Installation
The AI Core txAdmin recipe installs it. By hand:
Put it in place
Put the folder in resources/[ai]/ and add ensure ai-mysql to server.cfg before ensure ai-core and before any script that uses the database.
Set the connection
In env.cfg, set the connection string and let ai-mysql (and every ai-* script that uses the database) read it:
set mysql_connection_string "mysql://user:password@localhost/ai_core?charset=utf8mb4"
add_convar_permission ai-mysql read mysql_connection_string
add_convar_permission ai-core read mysql_connection_stringThe recipe's env.cfg already has the line for every ai-* script that needs it.
Remove oxmysql
Do not install oxmysql, mysql-async or ghmattimysql next to it. Scripts with dependency 'oxmysql' in their manifest start fine: ai-mysql counts as oxmysql.
Panel settings
None. ai-mysql is set with convars, the same ones oxmysql reads, so an existing server.cfg keeps working:
| Convar | What it changes | Default |
|---|---|---|
mysql_connection_string | Where the database is: mysql://user:password@host:port/database?options or the key=value; form (server=...;database=...;userid=...;password=...). | mysql://root@localhost |
mysql_slow_query_warning | Queries slower than this many milliseconds are warned in the console. | 200 |
mysql_resultset_warning | Results with more rows than this are warned in the console. | 1000 |
mysql_transaction_isolation_level | 1 REPEATABLE READ, 2 READ COMMITTED, 3 READ UNCOMMITTED, 4 SERIALIZABLE. | 2 |
ai_mysql_shared_pool_size | Connections ai-mysql keeps for all third-party scripts together. | 10 |
ai_mysql_pool_size | Connections each ai-* script keeps for itself. | 5 |
Commands
None. AI Core's admin command aicore_db [slow] prints database statistics of every resource in the server console (see ai-core).
Keybinds
None.
Works with other scripts
- Stands in for
oxmysql,mysql-asyncandghmattimysql(provide).@oxmysql/lib/MySQL.luaresolves to ai-mysql's copy. - ox_lib, QBCore, Qbox and ESX scripts that use oxmysql run on it.
Known limits
- The behaviour follows oxmysql 2.14.3. A script that needs a feature of a newer oxmysql may not find it.