Objective
You have an operational MySQL database. Analysts want to query it, but you don't want them on the primary, and you don't want to stand up a warehouse plus an ETL tool plus a scheduler to get the data somewhere safe.
This recipe exports a MySQL table to Parquet in your own object storage, on a
schedule, and then registers that Parquet as an ordinary SQL table you can
SELECT and JOIN against — reading it in place, with no load step.
Three things are worth knowing before you start:
- Your MySQL credentials are stored once as a connection and reused. The lake never keeps a second copy of them.
- Your S3 secret is encrypted at rest and never returned by the API — not the
plaintext and not the ciphertext. You'll see the access key id and
has_stored_secret: true, nothing more. - The export runs in a separate child process with its own memory budget, so a large table cannot take the database down with it.
On the blocks below. The setup is REST, so those blocks are
bashand are not executed by the recipe runner — run them yourself, in order. Thesqlblocks at the end are real and run against the table the setup creates.
Step 1: Configure the engine for lake exports
Two things are required: turn the lake on, and give the engine a key to encrypt stored destination secrets with.
# gateway.toml
cat >> gateway.toml <<'TOML'
[lake]
enabled = true
TOML
# A 32-byte key. Generate it ONCE and keep it with your other secrets --
# losing it means re-entering every destination credential.
export AIDB_ENCRYPTION_KEY="$(openssl rand -base64 32)"
synapcores --config gateway.toml
If you skip the key, the lake tells you so and stays off rather than starting in a state where it would store your S3 secret unencrypted:
ERROR Data lake failed to start: lake credential encryption: AIDB_ENCRYPTION_KEY
is not set, so lake credentials cannot be encrypted. /v1/lake/* will return 503.
For a throwaway dev instance only, AIDB_LAKE_ALLOW_DEV_KEY=1 uses a key that is
published in the source tree. Never use it anywhere real.
Grab an admin token for the rest of the recipe:
export AIDB=http://localhost:8080
export TOKEN=$(curl -sS -X POST $AIDB/v1/auth/login \
-H 'content-type: application/json' \
-d '{"username":"admin","password":"'"$ADMIN_PASS"'"}' | jq -r .data.access_token)
Step 2: Point SynapCores at your MySQL
The MySQL side is a data-sync connection. Note the field is database_name,
not database.
curl -sS -X POST $AIDB/v1/data-sync/connections \
-H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{
"name": "prod_mysql",
"connection_type": "mysql",
"host": "127.0.0.1",
"port": 3306,
"database_name": "laketest",
"username": "readonly_etl",
"password": "'"$MYSQL_PASS"'"
}' | jq '{id, name, database_name, status}'
{ "id": "cd56192c-9dd8-4d43-9583-0d48d3fa2437", "name": "prod_mysql",
"database_name": "laketest", "status": "active" }
Save the id and prove the engine can actually reach MySQL before you build a job on top of it:
export CONN=cd56192c-9dd8-4d43-9583-0d48d3fa2437
curl -sS -X POST $AIDB/v1/data-sync/connections/$CONN/test \
-H "Authorization: Bearer $TOKEN" | jq '{is_healthy, response_time_ms, error_message}'
{ "is_healthy": true, "response_time_ms": 0, "error_message": null }
Confirm the table you want is visible through the connection:
curl -sS $AIDB/v1/lake/sources/$CONN/tables -H "Authorization: Bearer $TOKEN" | jq
["enc_probe", "nums", "pings", "pings_perf", "pings_perf_seq", "recipe_lake_orders"]
Step 3: Declare where the Parquet goes
A destination is your bucket plus its credentials. This example targets MinIO
on localhost; for AWS drop endpoint, allow_http and path_style.
curl -sS -X POST $AIDB/v1/lake/destinations \
-H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{
"name": "analytics_bucket",
"kind": "s3",
"bucket": "synapcores-lake",
"prefix": "recipes/orders",
"region": "us-east-1",
"endpoint": "http://127.0.0.1:9010",
"allow_http": true,
"path_style": true,
"credentials": {
"kind": "static",
"access_key_id": "lakeadmin",
"secret_access_key": "'"$S3_SECRET"'"
}
}' | jq '{id, bucket, prefix, credentials_kind, access_key_id, has_stored_secret, status}'
{ "id": "f5a76092-c2d5-4239-84fa-bdd45d498c95", "bucket": "synapcores-lake",
"prefix": "recipes/orders/", "credentials_kind": "static",
"access_key_id": "lakeadmin", "has_stored_secret": true, "status": "untested" }
Note what came back: the access key id, which identifies the key, and
has_stored_secret: true. The secret itself is gone — a stored ciphertext handed
back to a client would be an offline attack on your encryption key.
"credentials": {"kind": "ambient"} instead uses the instance role / environment
credentials, which is what you want on EC2 or EKS.
Now test it. This is a real write-and-delete probe, not a ping:
export DEST=f5a76092-c2d5-4239-84fa-bdd45d498c95
curl -sS -X POST $AIDB/v1/lake/destinations/$DEST/test \
-H "Authorization: Bearer $TOKEN" | jq
{ "reachable": true, "can_list": true, "can_write": true, "can_delete": true,
"described": "s3://synapcores-lake/recipes/orders/ (us-east-1 via http://127.0.0.1:9010)" }
Do not skip this. A credential that can write but not list produces a job that half-works at 3am. Four separate answers is the point.
Step 4: Define the export job
curl -sS -X POST $AIDB/v1/lake/jobs \
-H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{
"name": "orders_to_lake",
"description": "orders -> parquet -> s3",
"source_connection_id": "'"$CONN"'",
"destination_id": "'"$DEST"'",
"tables": [{
"source_table": "recipe_lake_orders",
"lake_table": "orders_snap",
"mode": { "mode": "snapshot" },
"columns": [],
"order_by": ["order_id"],
"promote": [],
"transforms": []
}],
"schedule_cron": "0 3 * * *",
"enabled": true
}' | jq '{id, name, enabled, schedule_cron}'
The mode object is the one field worth reading twice:
| mode | what it writes | use it for |
|---|---|---|
{"mode":"snapshot"} |
a full copy per run, under snapshot_dt=YYYY-MM-DD |
mutable tables — customers, orders, inventory. No CDC to reason about. |
{"mode":"incremental","partition_column":"placed_at","granularity":"day"} |
only new rows, under dt=YYYY-MM-DD |
append-only facts — events, logs, pings |
"columns": [] means "resolve every column at run time" — and if the source
schema drifts from what was resolved, the run fails rather than silently
writing a different shape. order_by makes the file layout deterministic, which
is what lets you diff two snapshots.