Temporary tables and replication

TEMPORARY TABLE + statement vs row binlog — avoid replica surprises.

TEMPORARY TABLE is session-scoped. Replication makes that slippery.

Statement-based

CREATE TEMPORARY can replicate; later statements assume the temp exists on the replica session. Connection mismatch or parallel apply → breakages.

Row-based

Temps used only inside a session often need not exist on the replica if only permanent-table row events matter. Mixed mode still bites.

Rules

  1. Prefer binlog_format=ROW
  2. Avoid temps in replicated stored programs when possible
  3. Stage in ordinary tables with session-specific names if work must span replicated statements
  4. Test failover with the app’s real session patterns

Fine on a single server. Smell in heavily replicated OLTP paths.