gpt4 book ai didi

mysql - 如何从 MySQL 备份文件中删除空表

转载 作者:行者123 更新时间:2023-11-30 23:41:52 25 4
gpt4 key购买 nike

我有多个大型 MySQL 备份文件,它们都来自不同的数据库并且具有不同的模式。我想将备份加载到我们的 EDW 中,但我不想加载空表。

现在我正在备份文件上使用 AWK 删除空表,但我想知道是否有更好的方法来执行此操作。

如果有人感兴趣,这是我的 AWK 脚本:

编辑:我今天注意到这个脚本有一些问题,如果你想真正尝试使用它请小心。您的输出可能是错误的...我会发布我所做的更改。

# File: remove_empty_tables.awk
# Copyright (c) Northwestern University, 2010
# http://edw.northwestern.edu

/^--$/ {
i = 0;
line[++i] = $0; getline

if ($0 ~ /-- Definition/) {
inserts = 0;
while ($0 !~ / ALTER TABLE .* ENABLE KEYS /) {
# If we already have an insert:
if (inserts > 0)
print
else {
# If we found an INSERT statement, the table is NOT empty:
if ($0 ~ /^INSERT /) {
++inserts
# Dump the lines before the INSERT and then the INSERT:
for (j = 1; j <= i; ++j) print line[j]
i = 0
print $0
}
# Otherwise we may yet find an insert, so save the line:
else line[++i] = $0
}
getline # go to the next line
}
line[++i] = $0; getline
line[++i] = $0; getline
if (inserts > 0) {
for (j = 1; j <= i; ++j) print line[j]
print $0
}
next
} else {
print "--"
}
}

{
print
}

最佳答案

我想不出 mysqldump 中的任何选项会跳过备份中的空表。也许是 -where 选项,但不确定您是否可以做某事。恕我直言,第二个脚本中的后处理还不错。

关于mysql - 如何从 MySQL 备份文件中删除空表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2343017/

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