How to Fix MySQL Error 3748 (ER_CLIENT_GTID_UNSAFE_CREATE_DROP_TEMP_TABLE_IN_TRX_IN_SBR)
You trigger mysql error 3748 when a transaction creates or drops a temporary table under statement-based replication. You fix it by moving temporary table statements outside transactions or switching to row-based binary logging. Database teams see this failure when global transaction identifiers are active on the server. The database stops the query to protect replication state across nodes. If it let the query run, replicas could fall out of sync with the primary node. Understanding why the en
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You trigger mysql error 3748 when a transaction creates or drops a temporary table under statement-based replication. You fix it by moving temporary table statements outside transactions or switching to row-based binary logging.
Database teams see this failure when global transaction identifiers are active on the server. The database stops the query to protect replication state across nodes. If it let the query run, replicas could fall out of sync with the primary node. Understanding why the engine blocks this action helps you pick the best fix for your app.
Why mysql error 3748 happens in replication
The database engine uses error symbol ER_CLIENT_GTID_UNSAFE_CREATE_DROP_TEMP_TABLE_IN_TRX_IN_SBR and SQLSTATE HY000 for this failure. The official message warns that creating or dropping temporary tables inside transactions violates global transaction consistency. This rule applies whenever statement-based replication is in use.
Global transaction identifiers track every committed change across your database cluster. Each transaction gets one unique tag that travels from the primary server to every replica. This model requires every statement inside a transaction to support safe rollback if an error happens.
Temporary tables do not follow standard transaction rollback rules in this engine. When a query creates or drops a temporary table, the change cannot roll back cleanly. If a transaction fails halfway through, the temporary table change stays in place anyway.
Under statement-based logging, the server writes the raw query text to the binary log. Replicas read those statements and run them in the exact same order. If a transaction rolls back on the primary node, the binary log records a mismatch. The primary node and the replica now hold different temporary table states. To stop this split, the engine blocks the unsafe statement right away.
How to diagnose the failing transaction
You first need to find which app query or migration script triggers the block. Start by checking your app error logs for the HY000 state and error code 3748. The stack trace will point to the exact code path that opens the transaction.
Just-in-Time Access + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Look for code blocks that turn off auto-commit mode before making a temporary table. Many object-relational mappers wrap whole web requests inside a single transaction by default. A developer might add a temporary table for a fast report without noticing that outer wrapper.
You should also check the binary log format on the database session. Even if the server uses row-based logging globally, a session can still switch to statement mode. Background workers and older data tools often change their own session settings after they log in. Finding where the session format changes shows why the error only hits certain jobs.
How to fix the error in production
You have two safe ways to resolve this error without turning off replication checks. Never disable global transaction enforcement just to make a failing query pass. Turning off safety checks puts your whole replica set at risk during a crash.
The first fix is to change the binary log format to row-based logging. In row-based mode, the engine logs actual data row changes instead of raw statements. Changes to temporary tables are not written to the binary log at all in row mode. Because replicas never see the temporary table events, global transaction safety stays intact. You can set this format at the global level or on the client session.
The second fix is to rewrite the app workflow so temporary tables sit outside transactions. Have your app create the temporary table while auto-commit mode is still active. Next, start the transaction, run your data updates, and commit the work. Once the transaction finishes, drop the temporary table in auto-commit mode again. This pattern works well when you must keep statement-based logging for other reasons.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
What does SQLSTATE HY000 mean with error 3748?
SQLSTATE HY000 is a general error class for database engine rules. You must read the specific code 3748 to see the exact global transaction rule break.
Can I use temporary tables inside transactions with row-based logging?
Yes, row-based logging allows temporary table creation and removal inside open transactions. The engine skips logging temporary table events in row mode, which keeps replication safe.
Why do object-relational mappers trigger this error so often?
Many mappers open a transaction at the start of every task by default. Any temporary table query inside that task runs inside a transaction and hits the block.
Related guides
In this post