How to Show Tables in MySQL: Syntax and Examples
To show all tables in a MySQL database, use the
SHOW TABLES; command after selecting the database with USE database_name;. This command lists all tables available in the current database.Syntax
The basic syntax to list tables in MySQL is simple:
SHOW TABLES;- Lists all tables in the current database.USE database_name;- Selects the database you want to work with.
You must select a database first to see its tables.
mysql
USE your_database_name; SHOW TABLES;
Example
This example shows how to select a database and list its tables.
mysql
USE employees; SHOW TABLES;
Output
Tables_in_employees
-------------------
employees
departments
salaries
titles
Common Pitfalls
Common mistakes when showing tables include:
- Not selecting a database first with
USE, which causes an error or empty result. - Trying to show tables without proper permissions.
- Confusing
SHOW TABLESwith other commands likeSHOW DATABASES.
mysql
/* Wrong: No database selected */ SHOW TABLES; /* Right: Select database first */ USE employees; SHOW TABLES;
Quick Reference
| Command | Description |
|---|---|
| USE database_name; | Selects the database to work with |
| SHOW TABLES; | Lists all tables in the selected database |
| SHOW DATABASES; | Lists all databases on the server |
| SHOW TABLES LIKE 'pattern'; | Lists tables matching a pattern |
Key Takeaways
Always select the database first using USE before showing tables.
Use SHOW TABLES; to list all tables in the current database.
SHOW TABLES LIKE 'pattern'; helps filter tables by name.
Lack of permissions can prevent tables from showing.
SHOW TABLES is different from SHOW DATABASES.