@healthzkit/mysql package provides HealthAdapter helpers for mysql (callback driver) and mysql2 (promise API). Successful checks run a lightweight SQL probe (default SELECT 1) and return ok with metadata.latencyMs plus any fields from an optional metadata hook; failures return fail with the caught error.
Install the adapter package and one database client:
mysql and mysql2 are optional peers — install the driver you use.
Package entrypoints
@healthzkit/mysql-mysqlAdapter,mysql2Adapter, and their option types.@healthzkit/mysql/mysql-mysqlAdapteronly.@healthzkit/mysql/mysql2-mysql2Adapteronly.
Shared options
Both factories shareBaseMysqlOptions:
Pass either
connectionString or client (not both).
mysqlAdapter (mysql)
Peer: mysql >= 2.18.
Each check acquires a connection, runs connection.query(query), records round-trip latency, and **release()**s pooled connections in a finally block.
Connection string
PassconnectionString (and optional connectionOptions for extra pool settings). The adapter lazily imports mysql, parses a mysql:// or mysql2:// URL, and creates a shared internal Pool. Concurrent checks reuse that pool.
Existing client or pool
Passclient as:
- A
Pool: each check callspool.getConnection(), runs the query, then releases the connection. - A
Connection: the query runs on that instance; release is a no-op when the connection has noreleasemethod.
mysql2Adapter (mysql2)
Peer: mysql2 >= 3.
Uses the promise API from mysql2/promise. Each check acquires a connection, awaits connection.query(query), records latency, and releases pooled connections when applicable.
Connection string
PassconnectionString and connectionOptions (PoolOptions merged into the internal pool). The adapter lazily imports mysql2/promise, parses mysql:// or mysql2:// URLs, and reuses one internal pool across checks.
Existing client or pool
Passclient as a Pool or Connection from your app.
Connection strings
Both adapters accept URLs with themysql:// or mysql2:// scheme (default port 3306). Userinfo and database name come from the URL; additional pool settings go in connectionOptions.
Scheduling
For busy databases, pair these adapters with aschedule on the check so readiness reads cached results (see Scheduling).