Question

I wrote a simple bash script that generates mysqldump while locking the tables.

# 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}"

I see this error when I run this script

mysqldump: Couldn't find table: "TABLES"

but the strange thing is if I run these commands manually on the mysql prompt everything works as expected.

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

Can someone let me know if I am missing anything obvious?

Was it helpful?

Solution

You didn't close off Q3 with a semi-colon. Please see your statement below:

Q3="SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt ssc > /var/opt/backup.sql"

should be

Q3="SYSTEM /usr/bin/mysqldump -u root --master-data=1 --opt ssc > /var/opt/backup.sql;"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top