如何排除特定表的数据
我正在使用 mysqldump 为 MySQL 数据库创建规范的安装脚本。我想转储数据库中一半表的数据,但排除其他表中的数据。我知道以下两个命令:
--no-data
--ignore-table
但第一个命令适用于所有表,我相信第二个命令完全从转储中排除该表(例如创建语句),而不仅仅是桌子。有人知道如何使用 mysqldump 来实现我的目标吗?
编辑:
发现一个几乎重复的问题: mysql转储整个结构,但仅在单个命令中转储选定表中的数据
I am using mysqldump to create a canonical installation script for a MySQL database. I would like to dump the data for able half of the tables in the database, but exclude the data from the other tables. I am aware of the following two commands:
--no-data
--ignore-table
But the first applies to all tables, and I believe the second excludes the table entirely from the dump (e.g. create statements) not just the data in the table. Anyone know how to use mysqldump to achieve my goal?
EDIT:
found a near duplicate question: mysqldump entire structure but only data from selected tables in a single command
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对
mysqldump
运行两次单独的调用怎么样?一种创建数据库并忽略您不需要其中数据的表。另一个只是创建剩余的没有数据的表。您可以单独运行这两个脚本,也可以将它们连接在一起以创建最终脚本。How about running two separate calls to
mysqldump
? One to create the database and ignore the tables you don't want data from. The other to just create the remaining tables without data. You could either run the two scripts separately, or concatenate them together to create a final script.还有另一种选择可以完成所有工作(在对 mysql 本身的一次调用中),但可能永远不应该尝试它。
向 HP Lovecraft 致敬,(基于 Anuya 的 用于创建 INSERT 语句的存储过程)这里是不得调用的存储过程:
<强>注意:这个邪恶的、神秘的存储过程只能由疯子运行,下面的介绍纯粹是为了教育目的。
...值得庆幸的是,我没有目睹这个过程肯定会造成的令人痛苦的恐怖 MySQL 错误 #44009 ...
There is one other option to get everything done (in a single call to
mysql
itself) but it should probably never be attempted.In tribute to H.P. Lovecraft, (and based upon Anuya's stored procedure to create INSERT statements) here's The Stored Procedure Which Must Not Be Called:
Note: This unholy, arcane stored procedure would only be run by a madman and is presented below purely for educational purposes.
... thankfully, I was saved from witnessing the soul-wrenching horror this procedure must surely wreak by MySQL Bug #44009 ...
您可能会在这里找到您需要的内容:
http://www.electrictoolbox.com/mysqldump- selected-dump-data/
使用 where 语句可能是实现您想要做的事情的最简单方法。
You might find what you need here:
http://www.electrictoolbox.com/mysqldump-selectively-dump-data/
Using where statements is probably the easiest way to achieve what you are trying to do.