MySQL transaction over two databases on different servers

这一生的挚爱 提交于 2019-12-23 22:00:50

问题


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

回答1:


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.


来源:https://stackoverflow.com/questions/17597880/mysql-transaction-over-two-databases-on-different-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!