I assume you want to test the output of the your command (and not its return code). Then the syntax should look like
CMD_MYSQL="${MYSQL_DIR}mysql --user=${MYSQL_USER} --pass=${MYSQL_PASS} ..."
if [ "$($CMD_MYSQL --execute="SELECT COUNT(*) FROM information_schema.tables WHERE \
table_schema='$MYSQL_DB' and table_name='${tablename}_new';")" -eq 1 ]; then
echo "Renaming ($MYSQL_DB.$tablename)..."
$CMD_MYSQL --execute="RENAME TABLE $tablename to ${tablename}_old;"
else
echo "Table ${tablename}_new does not exist."
fi
note the extra $ in front of the parentheses.
The parentheses, without $ in front, create a subshell. With the $, they substitute with the output of the command in the parentheses.
If your query does outputs a more complex result than just a number, you might need to search for the number inside the result with something like:
if [[ "$($CMD_MYSQL --execute="SELECT COUNT(*) FROM information_schema.tables WHERE \
table_schema='$MYSQL_DB' and table_name='${tablename}_new';")" == *1* ]]; then
echo "Renaming ($MYSQL_DB.$tablename)..."
$CMD_MYSQL --execute="RENAME TABLE $tablename to ${tablename}_old;"
else
echo "Table ${tablename}_new does not exist."
fi
$CMD_MYSQL --execute="RENAME TABLE $tablename to ${tablename}_old";$CMD_MYSQL. Please see edited. The syntax error is in theifcondition.mysql? in the former case you don't need square brackets and-eqin the latter - you are missing$before(MYSQL