List Tables for a Specific Database Using MySQL SHOW TABLES

This post demonstrates how to list all tables for a specific MySQL database. I will use SHOW TABLES for this.

First, login as user root to your MySQL instance.


mysql -uroot -pYourPassword

Now change to the database you want to show tables for.


USE mysql;

Database changed

Now you can produce the list.

Run this:


SHOW TABLES;

+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.14 sec)

As with SHOW DATABASES, you can look for specific tables or tables containing specific text in their names.


SHOW TABLES LIKE 'slow_log';

+----------------------------+
| Tables_in_mysql (slow_log) |
+----------------------------+
| slow_log                   |
+----------------------------+
1 row in set (0.00 sec)

With wildcards…


SHOW TABLES LIKE 'time%';

+---------------------------+
| Tables_in_mysql (time%)   |
+---------------------------+
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
+---------------------------+
5 rows in set (0.00 sec)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestBuffer this pageShare on RedditShare on StumbleUpon
About Andy Hayes

Andy Hayes is a DBA working with SQL Server since version 7.0. He has a wonderful wife and two beautiful children. He loves database technology, playing cricket, and blogging. He is passionate about sharing his experiences as a DBA and learning more to further his understanding and knowledge. You can follow me on Twitter, check out my Facebook page or follow me on

Speak Your Mind

*


*