我编写了一个简单的bash脚本,在锁定表时生成mysqldump。
# Generate mysqldump that will be used on client side
Q1="USE test;"
Q2="FLUSH TABLES WITH READ LOCK;"
Q3="SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt ssc > /var/opt/backup.sql"
Q4="UNLOCK TABLES;"
SQL="${Q1}${Q2}${Q3}${Q4}"
# Run the mysql query commands
$MYSQL -uroot -e "$SQL"
SQL="${Q1}${Q2}${Q3}${Q4}"
我运行此脚本时看到此错误
mysqldump: Couldn't find table: "TABLES"
但奇怪的是,如果我在mysql提示符下手动运行这些命令,一切都按预期工作。
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt test > /var/opt/backup.sql
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql> Bye
如果我遗漏任何明显的东西,有人可以告诉我吗?
答案 0 :(得分:1)
你没有用分号关闭Q3。请参阅以下声明:
Q3="SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt ssc > /var/opt/backup.sql"
应该是
Q3="SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt ssc > /var/opt/backup.sql;"