简体   繁体   中英

MySQL transaction over two databases on different servers

Is it possible to make a MySQL transaction that changes databases on different servers?

I would need to:

  1. insert into the first database
  2. select from the first database
  3. insert into the second database
  4. if any of these fails, revert to the original state

As observed above, this question is very similar to Can I to a transaction across two MySQL databases? Whilst that question referred to different databases on the same server, its accepted answer still applies.

Indeed, as documented under XA Transactions :

Support for XA transactions is available for the InnoDB storage engine.

 [ deletia ] 

XA supports distributed transactions, that is, the ability to permit multiple separate transactional resources to participate in a global transaction. Transactional resources often are RDBMSs but may be other kinds of resources.

 [ deletia ] 

Some examples of distributed transactions:

 [ deletia ] 
  • An application performs actions that involve different database servers, such as a MySQL server and an Oracle server (or multiple MySQL servers), where actions that involve multiple servers must happen as part of a global transaction, rather than as separate transactions local to each server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM