How To List MySQL Tables with “show tables” SQL Query
MySQL stores given relation data in tables. While using tables we generally need to check and list existing tables. We can use different ways to list tables. In this tutorial we will learn how to use
show tables and
Select table_name in order to list and print table names.
Connect MySQL Interactive Shell
We need to connect or run command in MySQL to list table names. We will connect to the interactive MySQL server to run given commands. We will use
mysql command to connect local or remote MySQL interactive shell.
$ mysql -u root -p
In order to run given SQL commands and queries we need to specify the database we want to work. We will use
show databases and
use DATABASENAME command.
mysql> use mysql;
show tables SQL Query
Now we will run or
show tables query in this example. We can also use
SHOW TABLES which is uppercase version and have same affect with lowercase version. Do not skip to add semicolon to the end of the command.
mysql> show tables;
Show All Tables of MySQL Server with “Select table_name” Query
We have another alternative to
show tables query. This will list all tables created in connected MySQL instance.
mysql> SELECT table_name FROM information_schema.tables;
Show Tables Of Given Database with “Select table_name” Query
In this exmaple we will use
Select table_name query but we will filter for given database by using
where statement for
table_name column. We will only list database named
mysql in this example.
mysql> SELECT table_name FROM information_schema.tables where table_schema='mysql';