Skip to content

Configuration

Everything vSQL reads is a FiveM convar set in server.cfg. Nothing here is required beyond the connection itself - every option has a sensible default.

Connecting

You can point vSQL at the database two ways. A connection string wins if both are set.

Connection string

cfg
# URL form
set vsql_connection_string "mysql://user:password@host:3306/database"

# oxmysql-style key=value form (copy your old string across verbatim)
set vsql_connection_string "host=localhost;user=root;password=;database=fivem"

Discrete options

cfg
set vsql_host "localhost"
set vsql_port 3306
set vsql_user "root"
set vsql_password ""
set vsql_database "fivem"
# optional: connect over a unix socket / named pipe instead of TCP
set vsql_socket "/var/run/mysqld/mysqld.sock"

TIP

No vsql_database? vSQL still starts, but every query must fully-qualify table names (schema.table). It warns about this once on startup.

Full convar reference

Connection

ConvarDefaultDescription
vsql_connection_string(empty)URL (mysql://...) or key=value;... form. Overrides the discrete options below.
vsql_host / vsql_portlocalhost / 3306Server address.
vsql_user / vsql_passwordroot / (empty)Credentials.
vsql_database(empty)Default schema.
vsql_socket(empty)Unix socket or named-pipe path (skips TCP).
vsql_server_hintautoForce the server type: auto, mysql, or mariadb.

Pool

ConvarDefaultDescription
vsql_pool_size8Max pool connections.
vsql_max_idle(pool size)Max idle connections kept open; extras are closed. Set below vsql_pool_size to let idle connections drain.
vsql_idle_timeout60000Ms an idle connection lingers before being reaped.
vsql_connect_timeout30000Connection timeout in ms.
vsql_queue_limit0Max requests waiting for a free connection; 0 is unbounded. Set it to fast-fail under extreme load instead of queueing without limit.

Session

ConvarDefaultDescription
vsql_charsetutf8mb4Connection charset.
vsql_collationutf8mb4_unicode_ciSession collation.
vsql_timezoneZmysql2 timezone handling.
vsql_wait_timeout0If > 0, sets session wait_timeout and interactive_timeout.
vsql_query_timeout0If > 0, caps statement runtime (ms) server-side. MariaDB caps all statements; MySQL only caps read-only SELECTs.

Caching

ConvarDefaultDescription
vsql_cachefalseEnable the TTL + LRU result cache.
vsql_cache_size500Max cached result sets.
vsql_cache_ttl30000Cache entry TTL in ms.

Reliability & profiling

ConvarDefaultDescription
vsql_tx_retries2Extra attempts for a transaction/batch that hits a deadlock or lock-wait timeout. 0 disables retrying.
vsql_breaker_threshold10Consecutive failed reconnects (after the first successful connect) before the circuit breaker opens and queries fast-fail instead of queueing. 0 disables it.
vsql_breaker_reset30000Ms the breaker stays open before allowing a probe.
vsql_slow_query_warning150Slow-query threshold in ms (logged and surfaced in vsql top).
vsql_debug00 off, 1 lifecycle events, 2 logs every query with timing.

Read replicas

ConvarDefaultDescription
vsql_read_replicas(empty)Comma-separated replica connection strings. Reads round-robin across them; writes, locking reads, and transactions stay on the primary.
vsql_replica_hosts(empty)Comma-separated host[:port] replicas reusing the primary's user/password/database (the common "same creds, different host" case).
vsql_replica_cooldown10000Ms a replica that failed a query stays out of rotation before being retried.
cfg
# reuse the primary's credentials, just point at the replica hosts
set vsql_replica_hosts "10.0.0.2,10.0.0.3:3307"

A replica that errors with a connection failure is dropped from rotation for the cooldown and the read transparently falls back to the primary - a replica being down never blocks reads or trips the primary's reconnect.

Migrations

ConvarDefaultDescription
vsql_migrationstrueRun pending migrations on resource start.
vsql_migrations_dirmigrationsMigrations directory, relative to the resource.

Compatibility & casting

ConvarDefaultDescription
vsql_compatfalseClaim the oxmysql / ghmattimysql / mysql-async export namespaces so existing scripts route into vSQL. Enable only with those resources removed. See Compatibility.
vsql_typecastfalseoxmysql-compatible result casting: dates → epoch ms, TINYINT(1) / BIT(1) → boolean. Override per call with { typeCast: true | false }.

Updates

ConvarDefaultDescription
vsql_version_checktrueCheck GitHub for a newer release on start.
vsql_version_repovalerisn/vSQLowner/repo to check against (useful for forks).

Per-call options

A few settings can be overridden for a single query by passing an options object as the last data argument (before any callback):

js
// skip the result cache for this read even if caching is on globally
await exports.vSQL.single('SELECT money FROM players WHERE id = ?', [id], { cache: false });

// cancel server-side if this report runs longer than 3s
await exports.vSQL.query('SELECT ... big aggregate ...', [], { timeout: 3000 });

// force oxmysql-style casting on (or off) just here
await exports.vSQL.query('SELECT created_at FROM players', [], { typeCast: true });
cfg
set vsql_connection_string "mysql://root:pw@localhost:3306/fivem"
set vsql_pool_size 8
cfg
set vsql_connection_string "mysql://root:pw@localhost:3306/fivem"
set vsql_pool_size 16
set vsql_max_idle 4          # let idle connections drain between peaks
set vsql_slow_query_warning 100
set vsql_cache true          # only if your read/write mix benefits - see the warning below
cfg
set vsql_connection_string "mysql://root:pw@localhost:3306/fivem"
set vsql_debug 2             # log every query with timing
set vsql_slow_query_warning 50

WARNING

Result caching is opt-in and global: any write clears the entire cache to stay correct. It helps read-heavy workloads with repeated identical reads, and hurts write-heavy ones. Measure before enabling it in production, and reach for cacheClear("table") for targeted invalidation.

Released under the MIT License.