When using a bash script to execute remote MySQL queries, how can I know if the command was successful or not. Locally it would return an exit code. However, remotely it seems to send the query and if it is able to connect to the remote MySQL database it takes it as successful. Is there any way to view the output when executing remotely, like when executing locally. Here is the script:


RemoveID=`mysql -u root -proot -h -e "delete from table where ID = '$1'"`

2 Answers 2


SELECT statements will return number of rows into your shell variable.

For DELETE statements just append a SELECT ROW_COUNT() after your mysql query, so it would be in your example like:

RemoveID=`mysql -u root -proot -h -e "delete from table where ID = '$1';select row_count()"`

echo $RemoveID ROW_COUNT() 1


You could run a follow up query to check for the deleted ID in the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.