gpt4 book ai didi

mysql - Bash for 循环 : Backticks

转载 作者:行者123 更新时间:2023-11-29 07:24:26 27 4
gpt4 key购买 nike

我有这个代码

$db=test-1
for T in `mysql -u$dbUser -p$dbPass -N -B -e 'show tables from '$db`;
do
count=$((count+1))
mysqldump --skip-comments --compact --skip-lock-tables -u$dbUser -p$dbPass $db $T > $GIT_MYSQL/$T.sql
done
done;

它给了我这个错误

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 1

如何解决?

最佳答案

您没有正确声明数据库名称变量。尝试这样做:

$db=test-1
echo "My database is called $db"

将输出与此进行比较:

db=test-1
echo "My database is called $db"

考虑到上面的评论和正确的(我希望)引用,你的脚本应该可以工作:

dbUser="user"
dbPass="pass"
db="test-1"
for T in $(mysql -u "$dbUser" -p"$dbPass" -N -B -e "show tables from $db")
do
mysqldump --skip-comments --compact --skip-lock-tables -u "$dbUser" -p"$dbPass" "$db" "$T" > "$GIT_MYSQL/$T.sql"
done

关于mysql - Bash for 循环 : Backticks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34986766/

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