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?
mysqlshow is a good tool for this, here is test to check the presence of the database database_name
if mysqlshow -p${MYSQL_ROOT} 2>/dev/null| grep -q "database_name"
then
echo "Database exist."
else
echo "Database does not exist."
fi
Or a simple oneliner
echo "Database "`mysqlshow -p${MYSQL_ROOT} 2>/dev/null| grep -q "database_name" || echo "does not "`"exist."