Created
October 25, 2020 11:14
-
-
Save MarounMaroun/b554b2fd4d7d90e6a95febe6677377d8 to your computer and use it in GitHub Desktop.
Check if MySQL schema exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table_exists() { | |
db_url="$1" | |
user="$3" | |
password="$4" | |
schema="$2" | |
if [[ ! -z $(mysql -Ns -h"$db_url" -u"$user" -p"$password" -e "select schema_name from information_schema.schemata where | |
schema_name='${schema}';") ]]; then | |
echo "schema exists" | |
return 0 | |
fi | |
echo "schema doesn't exist" | |
return 1 | |
} | |
# usage | |
table_exists 127.0.0.1 user password schema |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment