Created
March 5, 2015 12:37
-
-
Save SpekkoRice/f88d8d7918b85dbfd85a 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; | |
if [ $(mysql -N -s -u root -p -e \ | |
"select count(*) from information_schema.tables where \ | |
table_schema='${table}' and table_name='${DB}';") -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
if [[ $(mysql --execute "SHOW TABLES FROM ${DB_NAME} LIKE '${DB_PREFIX}options';") -gt 0 ]]; then
This is what we settled on for now in SlickStack, thanks for the inspiration:
https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-wordpress-config.txt