Mysql List Of Tables In Database

5 min read

MySQL List of Tables in Database: A Complete Guide

Knowing how to retrieve a mysql list of tables in database is a fundamental skill for developers, database administrators, and data analysts. Consider this: whether you are troubleshooting an application, performing schema migrations, or simply exploring a new database, being able to enumerate tables quickly saves time and reduces errors. This article walks you through every reliable method to list tables in MySQL, explains what happens under the hood, and offers practical tips for filtering and extracting additional metadata Most people skip this — try not to..

This is where a lot of people lose the thread.


Why You Need to List Tables in MySQL

Before diving into the commands, it helps to understand the typical scenarios where a mysql list of tables in database is required:

  • Schema verification – Confirm that expected tables exist after a deployment or migration.
  • Ad‑hoc reporting – Identify which tables hold the data you need for a query or export.
  • Backup planning – Determine the size and number of tables before running a dump.
  • Security audits – Ensure no unauthorized tables have been created.
  • Development workflow – Generate code or ORM mappings based on the current schema.

Having a clear, repeatable way to list tables makes each of these tasks more efficient Worth knowing..


Method 1: Using the SHOW TABLES Statement

The simplest and most direct way to obtain a mysql list of tables in database is the SHOW TABLES command. It works from the MySQL client, any GUI tool, or programmatically via an API.

Basic Syntax

SHOW TABLES;

When executed, MySQL returns a result set with a single column named Tables_in_<database_name>. Each row contains the name of a table in the currently selected database Worth knowing..

Example

USE sales_db;
SHOW TABLES;

Output:

+----------------------+
| Tables_in_sales_db   |
+----------------------+
| customers            |
| orders               |
| order_items          |
| products             |
| suppliers            |
+----------------------+

Filtering with LIKE

If you only need tables that match a pattern, append a LIKE clause:

SHOW TABLES LIKE 'order%';

This returns tables whose names start with “order” (orders and order_items).

Using a Wildcard for More Complex Patterns

MySQL supports the % and _ wildcards inside the LIKE pattern:

  • % matches any sequence of characters.
  • _ matches exactly one character.
SHOW TABLES LIKE '%_log';   -- tables ending with "_log"
SHOW TABLES LIKE 'data_202[0-9]'; -- tables like data_2020, data_2021, etc.

Note: The SHOW TABLES statement only works for the default database or the database you explicitly specify with USE. To list tables from another database without switching context, see the next method It's one of those things that adds up. Which is the point..


Method 2: Querying the information_schema Database

For greater flexibility—especially when you need to list tables across multiple databases or join with other metadata—the information_schema schema is the go‑to source. It contains a wealth of views that describe every object in the MySQL server.

The TABLES View

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'your_database_name';

Replace your_database_name with the target database. This query returns the same list as SHOW TABLES but lets you add extra columns, filters, or joins Small thing, real impact. Nothing fancy..

Example with Additional Details

SELECT 
    table_name,
    table_type,
    engine,
    version,
    row_format,
    table_rows,
    avg_row_length,
    data_length,
    index_length,
    data_free,
    create_time,
    update_time,
    check_time,
    table_collation,
    checksum
FROM information_schema.tables
WHERE table_schema = 'sales_db'
ORDER BY table_name;

This query provides a snapshot of each table’s storage engine, approximate row count, size, and timestamps—useful for capacity planning or performance tuning Took long enough..

Listing Tables Across All Databases

Remove the table_schema filter to see every table in the server:

SELECT table_schema AS database_name,
       table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'   -- excludes views
ORDER BY table_schema, table_name;

You can further restrict the output to specific engines, character sets, or creation dates Still holds up..


Method 3: Using MySQL Command‑Line Options

When you prefer not to open an interactive MySQL session, the mysql client can execute a command and exit immediately. This is handy for scripts or cron jobs That's the whole idea..

One‑Liner to List Tables

mysql -u root -p -e "SHOW TABLES;" sales_db
  • -u root specifies the user.
  • -p prompts for a password (you can also provide it directly with -pYOUR_PASSWORD, though this is less secure).
  • -e "SHOW TABLES;" tells the client to run the statement and print the result.
  • sales_db is the database name.

Getting CSV‑Friendly Output

Add the --batch and --raw flags to produce tab‑separated values that are easy to parse:

mysql -u root -p --batch --raw -e "SHOW TABLES;" sales_db > tables.txt

The resulting file contains one table name per line, suitable for feeding into loops or other automation tools Still holds up..


Method 4: Using GUI Tools (MySQL Workbench, phpMyAdmin, etc.)

Graphical interfaces abstract the SQL commands but ultimately rely on the same underlying queries.

MySQL Workbench

  1. Open the Schemas pane on the left.
  2. Expand the target database.
  3. Expand the Tables node—you’ll see a list of all tables.
  4. Right‑click a table → Table Inspector to view details such as columns, indexes, and row counts.

You can also run a SQL query directly in the Workbench editor (SHOW TABLES;) and export the result set to CSV or Excel.

phpMyAdmin

  1. Select the database from the left sidebar.
  2. The main pane shows a list of tables with icons for engine type, row count, and size.
  3. Click the Structure tab to see a detailed view, or use the Search box to filter tables by name.

Both tools allow you to generate a mysql list of tables in database without typing any SQL, which is useful for quick visual checks.


Advanced Filtering and Metadata Extraction

Sometimes you need more than just table names. Below are common patterns for extracting useful information.

List Tables That Contain a Specific Column

SELECT DISTINCT table_name
FROM information_schema.columns
WHERE table_schema = 'sales_db'
Just Added

Freshly Posted

Keep the Thread Going

You Might Find These Interesting

Thank you for reading about Mysql List Of Tables In Database. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home