Skip to content

Instantly share code, notes, and snippets.

@MarounMaroun
Created October 25, 2020 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarounMaroun/b554b2fd4d7d90e6a95febe6677377d8 to your computer and use it in GitHub Desktop.
Save MarounMaroun/b554b2fd4d7d90e6a95febe6677377d8 to your computer and use it in GitHub Desktop.
Check if MySQL schema exists
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