← All writing

Resume a large export from a stable key

MySQL 8.0+ / InnoDBSources checked 2026-09-14

A large export fails halfway through. Restarting with a deep OFFSET is slow and can shift if rows are inserted or removed. A stable-key checkpoint gives the exporter a clearer resume position.

Fetch the next batch after the checkpoint

SELECT id, sku
FROM products
WHERE id > 12000 AND id <= 90000
ORDER BY id
LIMIT 1000;

The lower bound is the last completed key; the upper bound is a cutoff captured for this export. Those are illustrative values. Persist the checkpoint only after the corresponding output batch is durably recorded.

Define consistency expectations

A maximum ID cutoff excludes later inserts, but does not freeze updates to existing rows. If the export requires a point-in-time snapshot of every value, use a strategy that actually provides that guarantee. Do not call a key cutoff a complete snapshot.

Rows can be deleted between batches. Decide whether omission is acceptable and record the export's time and scope. If the ordering uses several columns, the checkpoint must capture the full ordering tuple, not only one field.

Test a failure between writing a batch and saving its checkpoint. The output should not silently duplicate rows on retry. A batch identifier or replaceable output segment can help make recovery deterministic. Keyset traversal solves access and resume ordering; durable output handling is a separate part of the export design.

Reference

Official documentation.