MySQL Distributed TRANSACTION statement operations

Source: Internet
Author: User


Statement:

XA {start| BEGIN} XID

XA END XID

XA PREPARE XID

XA COMMIT XID [one PHASE]

XA ROLLBACK XID

XA RECOVER


XA START XID | XA BEGIN XID

begins a transaction and puts the transaction into the active state, after which the SQL statement executed will be placed in the transaction.

XA END XID

puts the transaction in an idle state, indicating that the SQL operation within the transaction is complete.

Subsequent transactional operations can make XA PREPARE xid or xa COMMIT xid one PHASE.

XA PREPARE XID

to enable the preparation of transaction commits, the transaction state is placed in the prepared state.

If the transaction cannot be committed, the statement will fail.

Thereafter, the XC commit and XA ROLLBACK can be executed

XA COMMIT XID

The transaction is finally committed, the persistence is complete, and the transaction completes.

XA COMMIT XID One PHASE

executed after the XA end, the statement contains both XA prepare and XA COMMIT.

XA ROLLBACK XID

The transaction is rolled back and terminated.

Sample program:
  //  Create a connection to two databases, respectively, and create the respective tables, and the DDL statements cannot be executed during the transaction.       create_connection1 (&_g_connect1);       Create_connection2 (&_G_CONNECT2);       create_table_member (&_G_connect1) ;       create_table_member (&_G_CONNECT2);  //  Two databases create two distributed transaction       _g_connect1.direct_exec ("xa begin  ' Xa-trans '"), respectively;       _g_connect2.direct_exec ("xa start  ' Xa-trans '");   //   Write Data       insert_record_direct (&_G_CONNECT1) to two library tables separately;       insert_record_direct (&_G_CONNECT2);   // sql Operation Complete        _g_connect1.direct_exec ("xa end  ' Xa-trans '");       _ G_connect2.direct_exec ("xa end  ' Xa-trans '");  //  transaction Readiness Submission       _g_connect1.direct_exec ("xa prepare  ' Xa-trans '");       _g_connect2.direct_exec ("xa prepare  ' Xa-trans '");  //  transaction final submission        _g_connect1.direct_exec ("xa commit  ' Xa-trans '");       _g_connect2.direct_exec ("xa commit  ' Xa-trans '");    //  If a database is ready to commit failed, the transaction can be rolled back       //_g_connect1.direct_exec ("xa rollback " Xa-trans ' ");       //_g_connect1.direct_exec (" xa rollback  ' Xa-trans ' ");     // xa prepare and Xa commit, you can use a xa commit one phase statement to complete       _g_connect1.direct_exec ("xa commit  ' Xa-trans '  one  Phase ");       _g_connect2.direct_exec (" xa commit  ' Xa-trans '  one  phase ");


MySQL Distributed TRANSACTION statement operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.