-
-
Save amontalban/bec2aad4b0cd33776d821e20b952662d to your computer and use it in GitHub Desktop.
BASH: Check if MySQL Table 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
#!/bin/bash | |
checkIfMySQLTableExists() { | |
table=$1; | |
DB=$2; | |
if [ $(mysql -N -s -u root -p -e \ | |
"select count(*) from information_schema.tables where \ | |
table_schema='${DB}' and table_name='${table}';") -eq 1 ]; then | |
echo "Table ${table} exists! ..."; | |
else | |
echo "Table ${table} does not exist! ..." | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment