使用mysqldump跳过某些表 [英] Skip certain tables with mysqldump
本文介绍了使用mysqldump跳过某些表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从mysqldump命令限制某些表?
Is there a way to restrict certain tables from the mysqldump command?
例如,我将使用以下语法仅转储 > table1和table2:
For example, I'd use the following syntax to dump only table1 and table2:
mysqldump -u username -p database table1 table2 > database.sql
但是有一个类似的方法转储所有的表 > table1和table2?我没有在mysqldump文档中找到任何东西,所以是brute-force(指定所有的表名)是唯一的方法吗?
But is there a similar way to dump all the tables except table1 and table2? I haven't found anything in the mysqldump documentation, so is brute-force (specifying all the table names) the only way to go?
推荐答案
您可以使用 --ignore-table 选项。所以你可以做
You can use the --ignore-table option. So you could do
mysqldump -u username -p database --ignore-table=database.table1 > database.sql
如果你想忽略多个表,你可以使用这样一个简单的脚本
If you want to ignore multiple tables you can use a simple script like this
#!/bin/bash
PASSWORD=XXXXXX
HOST=XXXXXX
USER=XXXXXX
DATABASE=databasename
DB_FILE=dump.sql
EXCLUDED_TABLES=(
table1
table2
table3
table4
tableN
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
done
echo "Dump structure"
mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} --single-transaction --no-data ${DATABASE} > ${DB_FILE}
echo "Dump content"
mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} ${DATABASE} --no-create-info ${IGNORED_TABLES_STRING} >> ${DB_FILE}
这篇关于使用mysqldump跳过某些表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文