all components must commit, or all components must roll back. To manage a global transaction, it is necessary to take into account that any component or the connecting network might fail. 

The process for executing a global transaction uses two-phase commit (2PC). This takes place after the actions performed by the branches of the global transaction have been executed. 

1. In the first phase, all branches are prepared. That is, they are told by the TM to get ready to commit. Typically, this means each RM that manages a branch records the actions for the branch in stable storage. The branches indicate whether they are able to do this, and these results are used for the second phase. 

2. In the second phase, the TM tells the RMs whether to commit or roll back. If all branches indicated when they were prepared that they were able to commit, all branches are told to commit. If any branch indicated when it was prepared that it was not able to commit, all branches are told to roll back. 

In some cases, a global transaction might use one-phase commit (1PC). For example, when a Transaction Manager finds that a global transaction consists of only one transactional resource (that is, a single branch), that resource can be told to prepare and commit at the same time. 

## 13.3.8.1 XA Transaction SQL Statements 

To perform XA transactions in MySQL, use the following statements: 

XA {START|BEGIN} xid  [JOIN|RESUME] XA END xid  [SUSPEND [FOR MIGRATE]] XA PREPARE xid XA COMMIT xid  [ONE PHASE] XA ROLLBACK xid XA RECOVER [CONVERT XID] 

For XA START , the JOIN  and RESUME  clauses are recognized but have no effect. 

For XA END  the SUSPEND [FOR MIGRATE]  clause is recognized but has no effect. 

Each XA statement begins with the XA  keyword, and most of them require an xid  value. An xid  is an XA transaction identifier. It indicates which transaction the statement applies to. xid  values are supplied by the client, or generated by the MySQL server. An xid  value has from one to three parts: 

xid : gtrid  [, bqual  [, formatID  ]] 

gtrid  is a global transaction identifier, bqual  is a branch qualifier, and formatID  is a number that identifies the format used by the gtrid  and bqual  values. As indicated by the syntax, bqual  and formatID  are optional. The default bqual  value is ’’  if not given. The default formatID  value is 1 if not given. 

gtrid  and bqual  must be string literals, each up to 64 bytes (not characters) long. gtrid  and bqual  can be specified in several ways. You can use a quoted string ( ’ab’ ), hex string ( X’6162’ , 0x6162 ), or bit value ( b’ nnnn ’ ). 

formatID  is an unsigned integer. 

The gtrid  and bqual  values are interpreted in bytes by the MySQL server’s underlying XA support routines. However, while an SQL statement containing an XA statement is being parsed, the server works with some specific character set. To be safe, write gtrid  and bqual  as hex strings. 

