Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created October 20, 2011 17:37
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 abackstrom/1301756 to your computer and use it in GitHub Desktop.
Save abackstrom/1301756 to your computer and use it in GitHub Desktop.
Determine if a table exists (MySQL)

On a WordPress MU install that contains 21,511 tables.

Table does exist (DESCRIBE)

mysql@delphinus:~$ time printf "DESCRIBE wp_users ; %.0s" {1..100} | mysql -P 3308 wordpress -f &>/dev/null

real    0m0.094s
user    0m0.005s
sys     0m0.004s

Table does not exist (DESCRIBE)

mysql@delphinus:~$ time printf "DESCRIBE foo ; %.0s" {1..100} | mysql -P 3308 wordpress -f &>/dev/null

real    0m0.064s
user    0m0.003s
sys     0m0.004s

Table does exist (SHOW TABLES)

mysql@delphinus:~$ time printf "SHOW TABLES LIKE 'wp_users' ; %.0s" {1..100} | mysql -P 3308 wordpress -f &>/dev/null

real    0m9.195s
user    0m0.003s
sys     0m0.007s

Table does not exist (SHOW TABLES)

mysql@delphinus:~$ time printf "SHOW TABLES LIKE 'foo' ; %.0s" {1..100} | mysql -P 3308 wordpress -f &>/dev/null

real    0m9.116s
user    0m0.006s
sys     0m0.008s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment