How to Fix MySQL Error 1400 (ER_XAER_OUTSIDE)
You trigger mysql error 1400 when a session runs an XA command while local work is open. Fix it by finishing or rolling back the local transaction before starting the global XA transaction. MySQL uses the symbol ER_XAER_OUTSIDE and SQLSTATE XAE09 for this failure. The database returns the message XAER_OUTSIDE to show that some work happens outside a global transaction. You cannot mix standard local work and distributed XA work in the same active session. Root causes of mysql error 1400 in dat
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 1400 when a session runs an XA command while local work is open. Fix it by finishing or rolling back the local transaction before starting the global XA transaction.
MySQL uses the symbol ER_XAER_OUTSIDE and SQLSTATE XAE09 for this failure. The database returns the message XAER_OUTSIDE to show that some work happens outside a global transaction. You cannot mix standard local work and distributed XA work in the same active session.
Root causes of mysql error 1400 in database sessions
MySQL separates normal local transactions from global XA transactions. A session can run one type of work at a time. If your app disables autocommit, any standard read or write starts a local transaction right away.
When that same session tries to start an XA transaction next, the engine blocks the request. It throws mysql error 1400 to protect data integrity across the cluster. The database cannot merge uncommitted local changes into a new distributed transaction branch.
Session pools cause this problem often in busy systems. One app worker borrows a database session and disables autocommit for a quick local update. If the worker returns the session without a commit or rollback, the local transaction keeps the session active.
The next worker grabs that same pooled session to run a distributed job. When the worker sends the XA start command, the database rejects it with SQLSTATE XAE09. Leftover state from the first worker breaks the second worker.
Client drivers and Object Relational Mappers can also trigger ER_XAER_OUTSIDE. Many frameworks send hidden setup queries when they open a fresh session. If autocommit is off, those setup queries open a local transaction before your XA code runs.
How to diagnose and fix the failure in production
Start by checking the exact query log for the failing session. Look at the statements that ran right before the XA start command. You will usually find an uncommitted write or a session state change.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Check the autocommit status on your database sessions. If autocommit is off, your app must send an explicit commit or rollback after every local query. Doing this clears the session state before any global transaction begins.
Review how your app pool manages database sessions between requests. Set up your pool to reset session state each time a worker returns a session. A clean reset rolls back leftover local work and restores default settings.
Separate your local database pools from your distributed XA pools. Use one pool for standard queries and a second pool for XA work. This split stops local transactions from leaking into global transaction sessions.
Safe debugging in live database systems
Debugging transaction errors in production requires care. Do not grant full admin rights to developers just to inspect live session logs. Broad permissions create security risks and expose private records.
Use role-based controls to limit who can run diagnostic queries on production nodes. Keep audit logs of every query run during an incident review. Mask sensitive fields like emails, phone numbers, card numbers, and national IDs by rewriting matched fields in results.
Test your transaction fixes in a staging setup that matches production pool rules. Replay the exact sequence of local and global calls to confirm that ER_XAER_OUTSIDE no longer appears.
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 ER_XAER_OUTSIDE mean in MySQL?
ER_XAER_OUTSIDE is the symbol for mysql error 1400 with SQLSTATE XAE09. It means your session tried to run an XA operation while a local transaction was still active.
How does autocommit affect mysql error 1400?
When autocommit is off, any standard query starts an open local transaction. You must commit or roll back that work, or turn autocommit on, before starting an XA transaction.
Can session pooling trigger SQLSTATE XAE09?
Yes, a pooled session can hold an uncommitted local transaction from a past request. If the next request starts an XA transaction on that dirty session, MySQL throws error 1400.
Related guides
In this post