如何防止mysql复制某些记录
我的主-主复制工作成功,它工作正常,我所做的所有更改也将反映到从属设备。
但我不希望该从属设备反映所有更改 - 只有我想要的记录才应反映在从属设备上。怎样才能做到这一点呢?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以
在不想复制的语句之前执行此操作。它们不会被发送给奴隶。
或者,您可以在应用程序端配置每个连接来设置该值,然后
在需要时执行此操作。更多相同内容可以在 MySQL 复制:暂时阻止特定 SQL 语句复制到从属服务器? 上找到。
You can do
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
when you do want it. More of the same can be found on MySQL replication: temporarily prevent specific SQL statements replicating to the slaves?.
您可以阻止从属服务器处理特定数据库和单个表的更新,无论是作为白名单还是黑名单 - 请参阅 从属配置选项了解详细信息。
如果您的标准比这更复杂,您可能需要重新考虑。
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.
我能想到的唯一方法是在主服务器上创建一个视图,过滤掉您不想复制的记录,然后复制该视图。在从属设备上,“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.
如果不知道你想要实现什么目标,就很难说。
您可以防止通过复制对单个表或整个数据库进行更改(例如,建议您不要复制 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.