Common SQL Errors

MySQL Error 3199 ER_BINLOG_UNSAFE_XA: Statement is unsafe inside XA - Fix Guide

Galaxy Team
August 8, 2025

MySQL flags a statement inside an XA transaction as unsafe for statement-based replication and stops execution.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 3199 ER_BINLOG_UNSAFE_XA?

ER_BINLOG_UNSAFE_XA appears when MySQL detects a statement inside a distributed XA transaction that cannot be safely replicated with statement logging. Switch the server to row-based logging or move the statement outside the XA block to resolve the problem.

Error Highlights

Typical Error Message

ER_BINLOG_UNSAFE_XA

Error Type

Transaction Replication Error

Language

MySQL

Symbol

transaction. Concurrent XA transactions may deadlock on slaves when replicated using statements. ER_BINLOG_UNSAFE_XA was added in 5.7.20.

Error Code

3199

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 3199 ER_BINLOG_UNSAFE_XA?

MySQL raises ER_BINLOG_UNSAFE_XA when a data-changing statement inside an XA transaction cannot be guaranteed to replay correctly on a replica that uses statement-based logging.

The server stops the transaction to protect replication integrity, because concurrent distributed transactions could commit in different orders on replicas, leading to deadlocks or data drift.

What Causes This Error?

The error is triggered when the binlog_format parameter is STATEMENT or MIXED and the server encounters an INSERT, UPDATE, DELETE, or DDL command inside an XA START/END block.

MySQL 5.7.20 and later include extra checks that flag potentially unsafe patterns, especially when multiple XA transactions can interleave.

How to Fix ER_BINLOG_UNSAFE_XA

The safest fix is to switch binary logging to ROW format so every row change is replicated deterministically.

Alternatively, remove the offending statement from the XA transaction or execute the workload on a server dedicated to ROW logging.

Common Scenarios and Solutions

Ecommerce applications using two-phase commit across payment and inventory tables often hit the error during peak traffic; setting binlog_format=ROW resolves it without code changes.

Micro-services performing distributed commits across shards can avoid the error by committing locally first, then using XA only for idempotent confirmation records.

Best Practices to Avoid This Error

Configure new MySQL replicas with ROW logging by default when XA is in use.

Monitor the error log for ER_BINLOG_UNSAFE_XA and alert the data team so fixes can be applied before replication stalls.

Related Errors and Solutions

ER_BINLOG_UNSAFE_STATEMENT warns about unsafe statements outside XA; switching to ROW logging fixes both issues.

ER_XAER_DUPID indicates duplicate XID usage; ensure unique XIDs to prevent rollback loops.

Common Causes

Statement-based binlog format

STATEMENT or MIXED logging cannot guarantee replay order for XA transactions.

Mixed transactional engines

Updating non-transactional tables inside the XA block makes replication timing nondeterministic.

Interleaved distributed commits

Multiple concurrent XA START blocks on the same server increase deadlock risk on replicas.

Related Errors

ER_BINLOG_UNSAFE_STATEMENT

Unsafe non-XA statement detected with statement logging.

ER_XAER_DUPID

A duplicate XID was used in an XA START call.

ER_XA_RBTIMEOUT

An XA transaction exceeded the timeout period during rollback.

FAQs

Can I ignore ER_BINLOG_UNSAFE_XA if replication uses ROW?

If all replicas run ROW logging, the error will not appear; otherwise, ignoring it risks data drift.

Does the error affect single-instance databases?

The warning appears only when binary logging is enabled, so standalone instances without replication are unaffected.

Is XA still safe with binlog_format=MIXED?

No. MIXED switches to STATEMENT for many operations, so XA remains unsafe.

How does Galaxy help prevent this error?

Galaxy surfaces server variables and warns developers when XA code runs on a STATEMENT-logged server, promoting early fixes.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo