作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有多个大型 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/
我是一名优秀的程序员,十分优秀!