An XA transaction progresses through the following states:
- Use - XA STARTto start an XA transaction and put it in the- ACTIVEstate.
- For an - ACTIVEXA transaction, issue the SQL statements that make up the transaction, and then issue an- XA ENDstatement.- XA ENDputs the transaction in the- IDLEstate.
- For an - IDLEXA transaction, you can issue either an- XA PREPAREstatement or an- XA COMMIT ... ONE PHASEstatement:- XA PREPAREputs the transaction in the- PREPAREDstate. An- XA RECOVERstatement at this point includes the transaction's- xidvalue in its output, because- XA RECOVERlists all XA transactions that are in the- PREPAREDstate.
- XA COMMIT ... ONE PHASEprepares and commits the transaction. The- xidvalue is not listed by- XA RECOVERbecause the transaction terminates.
 
- For a - PREPAREDXA transaction, you can issue an- XA COMMITstatement to commit and terminate the transaction, or- XA ROLLBACKto roll back and terminate the transaction.
Here is a simple XA transaction that inserts a row into a table as part of a global transaction:
mysql> XA START 'xatest';
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO mytable (i) VALUES(10);
Query OK, 1 row affected (0.04 sec)
mysql> XA END 'xatest';
Query OK, 0 rows affected (0.00 sec)
mysql> XA PREPARE 'xatest';
Query OK, 0 rows affected (0.00 sec)
mysql> XA COMMIT 'xatest';
Query OK, 0 rows affected (0.00 sec)
        MySQL 9.4 supports detached XA transactions,
        enabled by the
        xa_detach_on_prepare system
        variable (ON by default). Detached
        transactions are disconnected from the current session following
        execution of XA
        PREPARE (and can be committed or rolled back by
        another connection). This means that the current session is free
        to start a new local transaction or XA transaction without
        having to wait for the prepared XA transaction to be committed
        or rolled back.
      
        When XA transactions are detached, a connection has no special
        knowledge of any XA transaction that it has prepared. If the
        current session tries to commit or roll back a given XA
        transaction (even one which it prepared) after another
        connection has already done so, the attempt is rejected with an
        invalid XID error (ER_XAER_NOTA)
        since the requested xid no longer
        exists.
Detached XA transactions cannot use temporary tables.
        When detached XA transactions are disabled
        (xa_detach_on_prepare set to
        OFF), an XA transaction remains connected
        until it is committed or rolled back by the originating
        connection. Disabling detached XA transactions is not
        recommended for a MySQL server instance used in group
        replication; see
        Server Instance Configuration, for more
        information.
      
        If an XA transaction is in the ACTIVE state,
        you cannot issue any statements that cause an implicit commit.
        That would violate the XA contract because you could not roll
        back the XA transaction. Trying to execute such a statement
        raises the following error:
      
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed
when global transaction is in the ACTIVE stateStatements to which the preceding remark applies are listed at Section 15.3.3, “Statements That Cause an Implicit Commit”.