Mysql-备份部分数据
有没有一种简单的方法可以在保持 FK 约束的同时从 mysql 数据库备份和恢复部分数据?
假设我有 2 个表
| CustomerId | CustomerName |
-----------------------------
| 12 | Bon Jovi |
| 13 | Seal |
,并且
| AddressId| CustomerId | City |
---------------------------------------
| 1 | 12 | London |
| 2 | 13 | Paris |
备份只会采用客户 12 和地址 1。
我的目标是从生产服务器获取大型数据库并在本地复制它,但包含部分数据。
由于架构相当复杂,因此无法选择自定义查询。另外,我不能依赖主表的存在来获取相关行。
谢谢
Is there an easy way to backup and restore partial data from a mysql database while maintaining the FK constraints?
Say if I have 2 tables
| CustomerId | CustomerName |
-----------------------------
| 12 | Bon Jovi |
| 13 | Seal |
and
| AddressId| CustomerId | City |
---------------------------------------
| 1 | 12 | London |
| 2 | 13 | Paris |
The backup would only take customer 12 and address 1.
My goal is to take a large database from a production server and replicate it locally, but with partial data.
Due to fairly complicated schema, a custom query is not an option. Also I can't rely on the existence of a main table from which one would get the related rows.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以手动复制特定客户,并通过在地址表上添加 FK 约束,复制将无法插入/更新这些记录。
用于复制数据库中的指定表 http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html#option_mysqld_replicate-do-table 。
使用此参数以静默方式跳过复制时的错误 http: //dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html#sysvar_slave_skip_errors 。
You could replicate specific customers manually and by adding an FK constraint on the address table replication will fail to insert/update these records.
For replicating specified tables in the db http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html#option_mysqld_replicate-do-table .
Use this parameter to silently skip errors on replication http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html#sysvar_slave_skip_errors .