-1

I just started working on a large project with hundreds of tables. I want to see all of the tables relating to DNS. I can't remember all of the table names that I'm working with, but I know they have "dns" in the name.

Is it possible to query the list of tables in a database and return just the names? It would be like show tables;, but filtering by table name.

An equivalent of SHOW TABLES FROM <database> WHERE table_name LIKE '%dns%';

Version Info: MySQL Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper

David
  • 208,112
  • 36
  • 198
  • 279
intrepid_em
  • 518
  • 8
  • 28
  • 2
    Possible duplicate of [Get table names using SELECT statement in MySQL](https://stackoverflow.com/questions/8334493/get-table-names-using-select-statement-in-mysql) – David Aug 17 '17 at 13:59
  • @David is this a duplicate though? I looked at that question, and it still doesn't example how to filter tables by name - the where statement is querying by database name. – intrepid_em Aug 17 '17 at 14:03
  • Yes, it's a duplicate. You're asking how to query the names of tables, which that question is also asking and has been answered. You can certainly change your `WHERE` clause any way you see fit. – David Aug 17 '17 at 14:05

3 Answers3

1

You can use the information_schema database;

SELECT * FROM information_schema.tables WHERE table_schema = <database> AND table_name LIKE '%dns%'

John Paul Ashenfelter
  • 3,135
  • 1
  • 22
  • 29
0

Yes, you can use this command for filter your tables

INFORMATION_SCHEMA.TABLES

Reference: https://dev.mysql.com/doc/refman/5.7/en/tables-table.html

Damon Dudek
  • 181
  • 6
0

Yes, It is possible.

show tables like 'pattern';

Where pattern is a string using wildcard characters "%","_"

  • % matches any number of characters.
  • _ matches exactly one character.

example : show tables like 'xxxxx%';

Refer: https://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html

Goutham R
  • 56
  • 4