How to Fix MySQL Error 3197 (ER_XA_RETRY)
You get mysql error 3197 when a database node cannot finish an XA commit right now. You fix this error by waiting a short time and running the commit step again. MySQL maps this issue to symbol ER_XA_RETRY and SQLSTATE HY000 in its logs. The server message states that the resource manager cannot commit the transaction branch yet. It asks your app to retry the action later. This error is a temporary block, not a full rollback of your data. Your branch stays in a prepared state until the node cle
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 get mysql error 3197 when a database node cannot finish an XA commit right now. You fix this error by waiting a short time and running the commit step again.
MySQL maps this issue to symbol ER_XA_RETRY and SQLSTATE HY000 in its logs. The server message states that the resource manager cannot commit the transaction branch yet. It asks your app to retry the action later. This error is a temporary block, not a full rollback of your data. Your branch stays in a prepared state until the node clears the local conflict.
What causes mysql error 3197 in your database
Distributed transactions use a two-phase commit protocol to keep data safe across nodes. First, the app asks every database node to prepare the transaction branch. Second, the app tells each node to commit the prepared changes. Error 3197 happens during that second phase.
Cluster replication lag is a common cause for this temporary stop. In multi-node clusters, a peer node might apply a conflicting write at the same moment. The local resource manager spots the lock conflict and pauses your XA commit. It returns code 3197 so the cluster can finish its background sync first.
Heavy disk writes or lock waits also trigger this message on busy servers. The storage engine holds the prepared state on disk so no records get lost. Still, it refuses to finalize the branch while internal flush queues are full. If your client app treats this code as a hard crash, branches stay stuck.
How to diagnose and fix ER_XA_RETRY safely
Start by checking which XA branches are still waiting inside the database engine. Ask a team member with read rights to view the list of prepared transactions. You will see the branch ID that failed to commit during the spike. Check your cluster health logs to see if replication queues were full then.
Next, update your app transaction manager to handle code 3197 with a backoff loop. When the app receives ER_XA_RETRY, it must pause for a few milliseconds. Then it should send the exact same commit request for that branch ID. Do not start a new transaction or send new data rows during this retry. In most cases, the second or third attempt finishes without any trouble.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Sometimes an app crashes before it can retry the stuck commit. When this happens, the prepared branch holds row locks and blocks other queries. An engineer must run a manual commit or rollback for that stuck branch ID. Keep this repair step safe by limiting who holds recovery roles in production. Never grant full admin rights to standard app accounts just to clear stuck branches. Also, keep data masking active on your query tools during this check. Masking rewrites emails, phone numbers, card numbers, and national IDs in query results.
How to prevent XA commit retries under heavy load
You can lower the rate of ER_XA_RETRY alerts by tuning your workload. Break huge distributed updates into smaller batches so locks clear much faster. Avoid writing to the exact same table rows from two cluster nodes at once. Direct all XA writes for one business domain to a single primary node.
Watch your disk latency and cluster network speed during peak traffic hours. Slow disks delay the commit phase and raise the chance of lock clashes. When your storage responds fast, the resource manager finishes XA commits on the first try.
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
Does mysql error 3197 mean my transaction rolled back?
No, the database did not roll back your data changes. The branch stays in a prepared state and waits for your retry.
How many times should an app retry after ER_XA_RETRY?
Most teams set up three to five retries with a short wait between tries. If the node still fails, alert an engineer to check cluster health.
Can I ignore stuck XA branches after this error?
No, stuck XA branches hold row locks and block other users from writing data. You must commit or roll back those branches to free the locks.
Related guides
In this post