Is it possible from within a bash script to check if a mysql database exists. Depending on the result then perform another action or terminate the script?
I give +1 to answer by @chown, but here's another alternative: If the bash script is running locally with the MySQL instance, and you know the path to the datadir, you can test:
if [ -d /var/lib/mysql/databasename ] ; then
# Do Stuff ...
fi
This also assumes your shell user running the script has filesystem-level privileges to read the contents of the MySQL datadir. This is often the case, but it is not certain.