You need to check the value of the $? variable provided by the shell. If you ran the failed command without the pipe it would give error code 1, if you check it after the pipe it will probably give error code 127. If it's not zero the operation has failed. (The short and sweet of it.)
Piping w/o error checking isn't really a good solution. Write this into a small shell script that checks the value of the $? variable:
#!/bin/bash
# run first command here...
mysqldump > output.dump
if [ "$?" = 0 ] ; then
# do the second thing here
cat output.dump | mysql
fi
if [ "$?" = 0 ] ; then
# this is checking now that the mysql program didn't throw an error
echo "Operation Successful!"
else
echo "Operation failed!"
fi
We're still using the pipe here, but validating the dump was successful before we use the data.
Just checking whether the "output" exists isn't valid because depending on the fates it may or may not create a filename once it begins the dump process. You should presume that any command would fail. The pipe mechanism is mostly for using for one-off commands and doesn't really have any error detection. If this process is something you do more than once then you should have a script that is checking the error codes.