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?
Also you can ask to use the database and then handle the exit code.
$ if mysql -uroot -pxxx -e "USE mysql"; then echo "exists"; fi
exists
$ if mysql -uroot -pxxx -e "USE doesnotexist"; then echo "exists"; fi
ERROR 1049 (42000) at line 1: Unknown database 'doesnotexist'