如何防止mysql复制某些记录

发布于 2024-09-15 10:17:29 字数 101 浏览 2 评论 0原文

我的主-主复制工作成功,它工作正常,我所做的所有更改也将反映到从属设备。

但我不希望该从属设备反映所有更改 - 只有我想要的记录才应反映在从属设备上。怎样才能做到这一点呢?

I have master-master replication working successfully, it works fine and all changes I make will reflect to slave also.

But I don't want that slave to reflect all changes - only such records that I want should reflect on slave. How can can do this?

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

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

发布评论

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

评论(4

飞烟轻若梦 2024-09-22 10:17:30

您可以

SET sql_log_bin=0;

在不想复制的语句之前执行此操作。它们不会被发送给奴隶。

或者,您可以在应用程序端配置每个连接来设置该值,然后

SET sql_log_bin=1;

在需要时执行此操作。更多相同内容可以在 MySQL 复制:暂时阻止特定 SQL 语句复制到从属服务器? 上找到。

You can do

SET sql_log_bin=0;

before the statement(s) you DO NOT want replicated. They will not be sent on to the slave.

Alternatively, you could configure on the application-side each connection to set that value, then do

SET sql_log_bin=1;

when you do want it. More of the same can be found on MySQL replication: temporarily prevent specific SQL statements replicating to the slaves?.

诗化ㄋ丶相逢 2024-09-22 10:17:30

您可以阻止从属服务器处理特定数据库和单个表的更新,无论是作为白名单还是黑名单 - 请参阅 从属配置选项了解详细信息。

如果您的标准比这更复杂,您可能需要重新考虑。

You can prevent the slave from processing updates for particular databases, and individual tables, either as a whitelist or a blacklist - see the slave configuration options for details.

If your criteria are more complex than that, you might need to rethink.

你爱我像她 2024-09-22 10:17:30

我能想到的唯一方法是在主服务器上创建一个视图,过滤掉您不想复制的记录,然后复制该视图。在从属设备上,“VIEW”表将是 MYISAM/InnoDB 而不是 VIEW。我知道你可以复制到不同的表类型(即 InnoDB->MyISAM),但我从未尝试过使用视图来做到这一点。

The only way I can think of is to create a VIEW on the master that filters out the records you don't want to replicate, then replicate that VIEW. On the slave the "VIEW" table would be MYISAM/InnoDB instead of a VIEW. I know you can replicate to different table types (i.e. InnoDB->MyISAM), but I never tried doing it with a View.

左岸枫 2024-09-22 10:17:30

如果不知道你想要实现什么目标,就很难说。

您可以防止通过复制对单个表或整个数据库进行更改(例如,建议您不要复制 mysql.* 表,因为您可能不希望复制 GRANT)(Paul Dixon 的回答提供了一些有关 如果您想防止复制某些类型的语句

(例如 DELETE 查询),那么您可以使用 MySQL 代理在复制这些查询之前重写这些查询。

如果您打算在从属服务器上对数据库进行分片(例如:在一台服务器上以 AM 开头,在另一台服务器上以 NZ 开头的记录),那么 MySQL 代理可能会再次帮助您。

Without knowing what you're trying to achieve, it is hard to say.

You can prevent changes to individual tables, or whole databases from being made through replication (for instance its recommended that you don't replicate the mysql.* tables as you might not want GRANTs getting replicated) (Paul Dixon's answer provides some more info about this)

If you want to prevent certain types of statements from being replicated (for instance DELETE queries) then you might be able to use MySQL proxy to rewrite those queries before replicating them.

If you're intending to shard the database on the slaves (eg: records starting A-M on one server and N-Z on another) then again MySQL proxy might be able to help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文