> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL relation source

> Observe a MySQL InnoDB table from your app.

Mount `@bijectionhq/app-sql` once per observed table. Replace the receiver binder in the [SQL mount example](https://docs.bijection.com/integrations/native-sql.md#mount-and-bind)
with `mysqlRelation("inventory.example:3306", login)`. Bind
it as `provider` and, as the mount's operator, call `source.initialize`. Rows and acquisition state use the SQL mount’s label.

Seal this connection JSON for the receiver with `bijection secret set`.
Grant the source account `SELECT` on the chosen table and use
`caching_sha2_password` or `mysql_native_password`. The receiver requires
TLS with a server certificate trusted by the deployment.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "username": "inventory_reader",
  "password": "<database password>",
  "database": "inventory",
  "table": "items",
  "key": [{"column": "account", "kind": "text"}, {"column": "id", "kind": "bigint"}],
  "columns": ["id", "name", "quantity"],
  "incarnation": "inventory-items-1"
}
```

Use an InnoDB base table and declare its full primary key in index order,
with one to eight signed `BIGINT` or text columns. Text keys use a full
index without prefix lengths. The cursor compares the whole tuple, with text
ordered by UTF-8 bytes. Record keys are JSON arrays of strings, at most 512
encoded bytes. Name one to sixteen distinct projection columns that MySQL
can encode with `JSON_OBJECT`. It allows up to 32 rows, 24 KiB of JSON per row and
48 KiB of encoded records per page. A page has its own read-only
repeatable-read transaction. A complete traversal may observe concurrent
changes, and later traversals refresh changed keys. The app keeps rows
whose keys disappear at the source.

The cursor binds the reviewed endpoint, server identity, relation metadata,
projection and configured incarnation. Set a new incarnation after a restore
or replacement that may reuse the observed metadata, and use the revision and
gap instant from source health to authorize the reset. Previously published keys
remain readable after the reset. This mode provides repeated observations.

## Binary log changes

Pass `mysqlBinlog({ endpoint: "inventory.example:3306", … })` with its receiver block: `label`, `credential: login`, `requests: { retain, message }`, a reviewed `isolation` statement and a retention budget `hold` (bytes such as `"8GiB"`, or an age). At the budget the source releases its log (`onHold: "release"`), which is a gap. Use it as `provider` on a fresh mount. Use MySQL 8.4 and the same TLS requirements.
For this mode set `"key": "id"` in the sealed credential and use a single
signed `BIGINT` primary key. Grant `REPLICATION CLIENT` and `REPLICATION SLAVE` in addition
to the source table's read permission. The connector checks for an
unfiltered binary log with GTIDs and enforced GTID consistency, row-based
events, full row images and full row metadata. Require CRC32 checksums
and disable partial JSON updates and transaction compression for the
source's writers.

The first successful read records the current log file and offset. The
mount publishes changes committed after that point. Existing rows enter the
mount when a later transaction writes them. The mount applies one complete
transaction's changes to the selected relation with its cursor. Deletes
remove keys, and a primary-key update removes the old key and adds the new
one in the same commit. Projected cells use an exact `{ kind, text }`
representation or JSON null.

A read inspects up to 512 events. The publication holds up to 32 changes,
24 KiB of JSON per row and 48 KiB of encoded changes. Oversized
transactions leave the retained cursor at a commit boundary. A DDL
statement anywhere in the observed log stops the capture for repair.
Health reports the oldest available file, observed head and retained
position as `file:offset` strings. A purged, shortened or replaced file
stops automatic advancement. Use a fresh mount and update the configured
incarnation after replacing or restoring the source.

## Write a declared relation

Follow the [parameterized SQL write guide](https://docs.bijection.com/integrations/native-sql.md#parameterized-sql-writes)
for the writer binding, composite and text keys, declared projection and
provider affected-row evidence.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.