Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show MySQL tables starting with prefix?

Tags:

mysql

I'm trying to get MySQL tables by name starting with prefix "someprefix_", but I get wrong (?) results.
I tried to execute SHOW COLUMNS LIKE 'someprefix_%' but problem is, that I have also tables with prefix "someprefix2_" and those tables are also being returned in the result.

Is there a way to exclude tables with a similar prefix from the result?

like image 832
shad Avatar asked Apr 09 '13 15:04

shad


1 Answers

To list all tables with some prefix, "any number of symbols" wildcard (%), should be used.

_ is also a wildcard, representing any single symbol, and therefore it should be escaped.

Therefore, given your prefix is someprefix_, then

SHOW TABLES LIKE 'someprefix\_%'

would work

like image 108
Your Common Sense Avatar answered Oct 19 '22 17:10

Your Common Sense