gpt4 book ai didi

mysql - 如何从 mysqldump 中删除表

转载 作者:可可西里 更新时间:2023-11-01 06:34:38 24 4
gpt4 key购买 nike

如何删除包含大量表的 mysqldump 中一个大表的输出?

我有一个 6 GB 大的数据库转储,但其中 90% 只是一个日志记录表“cache_entries”,我的备份中不再需要它。

如何轻松删除转储中描述大型日志记录表的位?

我发现了这个: http://gtowey.blogspot.de/2009/11/restore-single-table-from-mysqldump.html

例子:

grep -n 'Table structure' dump.sql

然后例如:

sed -n '40,61 p' dump.sql > t2.sql

但是我该如何根据需要更改它呢?

最佳答案

您可以使用 'n,n d' 来删除某些行。我想在你的情况下你确实想要有问题的表,但不想要数据?

更改 grep 命令以包含“为表转储数据”:

grep -n 'Table structure\|Dumping data for table' dump.sql 19:-- Table structure for table `t1`37:-- Dumping data for table `t1`47:-- Table structure for table `t2`66:-- Dumping data for table `t2`76:-- Table structure for table `t3`96:-- Dumping data for table `t3`

现在,如果您不想要 t2 的数据,您可以使用:

sed '66,75 d' dump.sql > cleandump.sql

关于mysql - 如何从 mysqldump 中删除表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9895995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com