To perform XA transactions in MySQL, use the following statements:要在MySQL中执行XA事务,请使用以下语句:
XA {START|BEGIN}xid
[JOIN|RESUME] XA ENDxid
[SUSPEND [FOR MIGRATE]] XA PREPARExid
XA COMMITxid
[ONE PHASE] XA ROLLBACKxid
XA RECOVER [CONVERT XID]
For 对于XA START
, the JOIN
and RESUME
clauses are recognized but have no effect.XA START
,可以识别JOIN
和RESUME
子句,但不起作用。
For 对于XA END
the SUSPEND [FOR MIGRATE]
clause is recognized but has no effect.XA END
,可以识别SUSPEND [For MIGRATE]
子句,但不起作用。
Each XA statement begins with the 每个XA语句都以XA
keyword, and most of them require an xid
value. XA
关键字开头,其中大多数语句都需要xid
值。An xid
is an XA transaction identifier. xid
是XA事务标识符。It indicates which transaction the statement applies to. 它指示该语句适用于哪个事务。xid
values are supplied by the client, or generated by the MySQL server. xid
值由客户端提供,或由MySQL服务器生成。An xid
value has from one to three parts:xid
值由一到三部分组成:
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. gtrid
是全局事务标识符,bqual
是分支限定符,formatID
是标识gtrid
和bqual
值使用的格式的数字。As indicated by the syntax, 如语法所示,bqual
and formatID
are optional. bqual
和formatID
是可选的。The default 如果未给定,则默认bqual
value is ''
if not given. bqual
值为''
。The default 如果未给定,则默认formatID
value is 1 if not given.formatID
值为1。
gtrid
and bqual
must be string literals, each up to 64 bytes (not characters) long. gtrid
和bqual
必须是字符串文字,每个文字的长度不得超过64字节(不是字符)。gtrid
and bqual
can be specified in several ways. gtrid
和bqual
可以用几种方式指定。You can use a quoted string (您可以使用带引号的字符串('ab'
), hex string (X'6162'
, 0x6162
), or bit value (b'
).nnnn
''ab'
)、十六进制字符串(X'6162'
、0x6162
)或位值(b'nnnn'
)。
formatID
is an unsigned integer.formatID
是一个无符号整数。
The gtrid
and bqual
values are interpreted in bytes by the MySQL server's underlying XA support routines. gtrid
和bqual
值由MySQL服务器的底层XA支持例程以字节为单位进行解释。However, while an SQL statement containing an XA statement is being parsed, the server works with some specific character set. 但是,当解析包含XA语句的SQL语句时,服务器会处理某些特定的字符集。To be safe, write 为了安全起见,将gtrid
and bqual
as hex strings.gtrid
和bqual
写为十六进制字符串。
xid
values typically are generated by the Transaction Manager. xid
值通常由事务管理器生成。Values generated by one TM must be different from values generated by other TMs. 一个TM生成的值必须不同于其他TM生成的值。A given TM must be able to recognize its own 给定的TM必须能够在xid
values in a list of values returned by the XA RECOVER
statement.XA RECOVER
语句返回的值列表中识别自己的xid
值。
XA START
starts an XA transaction with the given xid
xid
value. XA START
使用给定的xid
xid
值来启动一个XA事务。Each XA transaction must have a unique 每个XA事务必须具有唯一的xid
value, so the value must not currently be used by another XA transaction. xid
值,因此该值当前不能由另一个XA事务使用。Uniqueness is assessed using the 使用gtrid
and bqual
values. gtrid
和bqual
值评估唯一性。All following XA statements for the XA transaction must be specified using the same 必须使用与xid
value as that given in the XA START
statement. XA START
语句中给定值相同的xid
值指定XA事务的所有以下XA语句。If you use any of those statements but specify an 如果使用这些语句中的任何一条,但指定的xid
value that does not correspond to some existing XA transaction, an error occurs.xid
值与某些现有XA事务不对应,则会发生错误。
One or more XA transactions can be part of the same global transaction. 一个或多个XA事务可以是同一全局事务的一部分。All XA transactions within a given global transaction must use the same 给定全局事务中的所有XA事务必须在gtrid
value in the xid
value. xid
值中使用相同的gtrid
值。For this reason, 出于这个原因,gtrid
values must be globally unique so that there is no ambiguity about which global transaction a given XA transaction is part of. gtrid
值必须是全局唯一的,这样就不会对给定XA事务属于哪个全局事务产生歧义。The 对于全局事务中的每个XA事务,bqual
part of the xid
value must be different for each XA transaction within a global transaction. xid
值的bqual
部分必须不同。(The requirement that (要求bqual
values be different is a limitation of the current MySQL XA implementation. It is not part of the XA specification.)bqual
值不同是当前MySQL XA实现的一个限制。它不是XA规范的一部分。)
The XA RECOVER
statement returns information for those XA transactions on the MySQL server that are in the PREPARED
state. XA RECOVER
语句返回MySQL服务器上处于PREPARED
状态的XA事务的信息。(See Section 13.3.8.2, “XA Transaction States”.) (请参阅第13.3.8.2节,“XA事务状态”。)The output includes a row for each such XA transaction on the server, regardless of which client started it.输出包括服务器上每个此类XA事务的一行,而不管是哪个客户端启动的。
XA RECOVER
requires the XA_RECOVER_ADMIN
privilege. XA RECOVER
需要XA_RECOVER_ADMIN
权限。This privilege requirement prevents users from discovering the XID values for outstanding prepared XA transactions other than their own. 此权限要求防止用户发现自己事务以外的未完成准备XA事务的XID值。It does not affect normal commit or rollback of an XA transaction because the user who started it knows its XID.它不会影响XA事务的正常提交或回滚,因为启动它的用户知道它的XID。
XA RECOVER
output rows look like this (for an example xid
value consisting of the parts 'abc'
, 'def'
, and 7
):XA RECOVER
输出行如下所示(例如,由'abc'
、'def'
和7
部分组成的xid
值):
mysql> XA RECOVER;
+----------+--------------+--------------+--------+
| formatID | gtrid_length | bqual_length | data |
+----------+--------------+--------------+--------+
| 7 | 3 | 3 | abcdef |
+----------+--------------+--------------+--------+
The output columns have the following meanings:输出列具有以下含义:
formatID
is the formatID
part of the transaction xid
formatID
是事务xid
的formatID
部分
gtrid_length
is the length in bytes of the gtrid
part of the xid
gtrid_length
是xid
的gtrid
部分的长度(以字节为单位)
bqual_length
is the length in bytes of the bqual
part of the xid
bqual_length
是xid
的bqual
部分的长度(以字节为单位)
data
is the concatenation of the gtrid
and bqual
parts of the xid
data
是xid
的gtrid
和bqual
部分的串联
XID values may contain nonprintable characters. XID值可能包含不可打印的字符。XA RECOVER
permits an optional CONVERT XID
clause so that clients can request XID values in hexadecimal.XA RECOVER
允许一个可选的CONVERT XID
子句,以便客户端可以请求十六进制的XID值。