Reputation: 1
Running a bash script executing MySQL commands, I get an error on this line.
$MYSQL_BIN $DATABASE -e \
"ALTER TABLE `nodes` ADD COLUMN `created_date` int(32) AFTER `address`";
The error is created_date: command not found
As well as on this line:
$MYSQL_BIN $DATABASE -e \
"UPDATE `nodes` SET `created_date` = UNIX_TIMESTAMP() WHERE `created_date`
IS NULL AND `address` IS NOT NULL";
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 'SET = UNIX_TIMESTAMP() WHERE IS NULL AND IS NOT NULL' at line 1.
I believe the first error is because I'm probably not escaping quotes?
Upvotes: 0
Views: 2497
Reputation: 10174
Bash uses bactick operator (`
) to indicate command substitution, that is, substitution of the standard output from one command into a line of text defining another command.
So you should either use single quotes instead of double ones or escape the backticks properly:
$MYSQL_BIN $DATABASE -e
'ALTER TABLE `nodes` ADD COLUMN `created_date` int(32) AFTER `address`';
or
$MYSQL_BIN $DATABASE -e
"ALTER TABLE \`nodes\` ADD COLUMN \`created_date\` int(32) AFTER \`address\`";
Upvotes: 4