有没有办法在同一个事务中将多个 SQL 发送到不同的服务器?

发布于 2024-09-06 06:45:33 字数 149 浏览 5 评论 0原文

在我的系统中,我们执行操作,为了报告的目的,我们将该操作记录在另一台服务器上(如果感兴趣的话,星型模式)。 显然,我需要操作更新/插入与日志记录位于同一事务中。
那么,有没有办法在同一个事务中包含两个不同的sql到两个不同的服务器?
现在我在代码级别(php)进行管理

In my system we do action, and for reporting sake we log that action on another server (star schema if it interests).
Obviously I need the action updates/inserts be in the same transaction as the logging.
So, is there a way to include two different sqls to two different servers in the same transaction?
Right now I manage that in the code level (php)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

揪着可爱 2024-09-13 06:45:33

单独使用 MySQL 是不可能实现这一点的。虽然MySQL确实有一个联合存储引擎 (即:远程访问其他MySQL服务器)它不支持事务。这意味着您无法直接通过 MySQL 协调多服务器事务。 MySQL确实支持XA 用于 InnoDB 表,因此您可以在 MySQL 中使用外部事务管理器,但 PHP 不支持 XA。一般来说,这被认为是企业级功能,您可以使用 JavaC#/.NET

This isn't possible with MySQL alone. While MySQL does have a Federated Storage Engine (ie: remote access to other MySQL servers) it doesn't support transactions. That means you can't coordinate a multi-server transaction directly through MySQL. MySQL does support XA for InnoDB tables, so you can use an external transaction manager with MySQL, but PHP doesn't have any support for XA. Generally this is considered an Enterprise-level feature, and you'd implement using Java or C#/.NET.

北恋 2024-09-13 06:45:33

您可以使用分布式事务协调器。

< a href="http://support.microsoft.com/kb/301600" rel="nofollow noreferrer">配置 DTC。

玩物 2024-09-13 06:45:33

复杂的方法是:

  1. 在同一服务器上创建相同的表。
  2. 使此服务器
  3. 成为主服务器

如果您希望日志表不是很大,您可以这样做:

  1. 第一个表名设置_tmp
  2. 在从属 log_tmp 上创建 插入时触发并更新以将数据复制到日志表
  3. 一段时间后从 log_tmp 中删除掌握一些数据。

Complicated way is:

  1. create same table on same server.
  2. Make this server master
  3. Set replica an this table

if you want that log table be not very big you can do:

  1. first table name set _tmp
  2. create on slave log_tmp trigger on insert and update to copy data to log table
  3. after some time to delete from log_tmp in master some data.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文