How to Fix MySQL Error 1397 (ER_XAER_NOTA)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1397 when a client calls an unknown transaction ID. To fix it, match the exact XID string or recover pending transactions. In the database engine, this failure uses the symbol ER_XAER_NOTA and SQLSTATE XAE04. The server returns the message XAER_NOTA: Unknown XID when the ID is missing. Teams see this issue during two-phase commits across multiple data nodes. What causes mysql error 1397 in distributed transactions A two-phase commit uses a global transaction ID, known as

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 1397 when a client calls an unknown transaction ID. To fix it, match the exact XID string or recover pending transactions.

In the database engine, this failure uses the symbol ER_XAER_NOTA and SQLSTATE XAE04. The server returns the message XAER_NOTA: Unknown XID when the ID is missing. Teams see this issue during two-phase commits across multiple data nodes.

What causes mysql error 1397 in distributed transactions

A two-phase commit uses a global transaction ID, known as an XID. The app sends this XID to start, end, prepare, and commit work. If the database cannot find the XID in memory, it throws this error.

Connection drops are the most common cause in production systems. When a client session drops before the prepare phase, the server rolls back work. The database also wipes the XID from its internal state table. If the app reconnects and tries to finish the work, the XID is gone.

Connection pools also trigger this failure when they route commands to different sessions. An unprepared transaction belongs to one specific session on the server. If a pool sends the end command over a new session, the lookup fails.

Timeouts and deadlocks inside the storage engine also clear active transactions. When a lock wait times out, the engine aborts the branch and drops the XID. The transaction manager may not know about this abort until it tries to commit.

Finally, typos or format changes in the XID string cause lookup misses. The global ID, branch qualifier, and format ID must match across every step.

How to diagnose and fix ER_XAER_NOTA safely

Start by checking the list of prepared transactions on the database server. Run the recovery query to view all XIDs that survived in a prepared state. Compare those values against the XID in your app error logs.

If the XID is not in the recovery list, the branch already ended. It either rolled back after a drop or committed in an earlier retry. Your app should treat the branch as gone and start a new workflow.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, check how your app pool handles sessions during a distributed transaction. Pin the database connection to the worker thread from start to prepare. Never return a connection to the pool while a transaction branch is active.

Check your database error logs for deadlocks or lock wait timeouts. If inner queries fail, the engine may abort the whole transaction branch early. Catch these query errors in the app before sending the end or prepare step.

Do not grant superuser roles to app accounts just to run recovery queries. Keep recovery permissions limited to a dedicated admin role or a recovery worker. When engineers inspect live databases, use data masking to rewrite sensitive fields in results. Masking rewrites emails, phone numbers, card numbers, and national IDs during live checks.

Preventing unknown XID errors in your app

Set clear timeout rules in your transaction manager and database server. Make sure the app timeout is shorter than the database session timeout. This prevents the server from dropping idle branches while the app is still working.

Add idempotent retry logic to your transaction coordinator for commit and rollback steps. If a network blip hides a commit reply, a retry will hit this error. Your coordinator should log the unknown XID state and check the main transaction log.

Keep work inside a distributed branch as short and fast as possible. Do not call slow external APIs while holding an open database branch. Fast branches hold locks for less time and rarely hit session drops.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What does SQLSTATE XAE04 mean in MySQL?

SQLSTATE XAE04 maps to error 1397 and the symbol ER_XAER_NOTA. It means the server could not find the requested XID for a command.

Can a connection pool cause mysql error 1397?

Yes, if the pool sends transaction steps across different database sessions, this error occurs. Pin the session to one thread until the prepare or commit step finishes.

How do I check if a transaction is still prepared?

Run the standard recovery statement on the database to list prepared XIDs. If your XID is missing from the output, the database already closed it.

The query runs. The emails stay hidden.