[英]Excluding tables from “show tables” in a scripted mysqldump
I would like to update the following bash script, which individually dumps each table in a given schema:我想更新以下 bash 脚本,它单独转储给定模式中的每个表:
for t in $(mysql -NBA -h db_host -u db_user -pdb_pass db_name -e 'show tables')
do
mysqldump -h db_host -u db_user -pdb_pass db_name $t > db_name.$t.sql
to exclude some tables that do not need to be picked up by this script.排除一些不需要此脚本拾取的表。 This is what I mean:
这就是我的意思:
for t in $(mysql -NBA -h db_host -u db_user -pdb_pass db_name -e 'show tables where `Tables_in_db_name` not like 'table1' and `Tables_in_db_name` not like 'table2'')
do
mysqldump -h db_host -u db_user -pdb_pass db_name $t > db_name.$t.sql
The sql is fine in itself, but I can't get it to run inside the -e command. sql 本身很好,但我无法让它在 -e 命令中运行。 Obviously in this example, the problem is the -e command's opening and closing apostrophes.
显然,在这个例子中,问题在于 -e 命令的开始和结束撇号。 I have tried:
我努力了:
With no success.没有成功。 Does anybody know how to accommodate apostrophes and back ticks within these confines?
有人知道如何在这些范围内容纳撇号和反引号吗?
Thank you.谢谢你。
The SQL is fine in itself, but I can't get it to run inside the
-e
command.SQL 本身很好,但我无法让它在
-e
命令中运行。 Obviously in this example, the problem is the-e
command's opening and closing apostrophes.显然,在这个例子中,问题在于
-e
命令的开始和结束撇号。
Right.正确的。 I assume it will be necessary to escape the backticks.
我认为有必要避开反引号。 After a short test it seems that
经过短暂的测试后,似乎
mysql -NBA -h ${DB_HOST} -u "${DB_USER}" -p" ${DB_PASS}" ${DB_NAME} -e "SHOW TABLES WHERE \`Tables_in_${DB_NAME}\` NOT LIKE 'table%'"
is working.正在工作中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.