Listing tables in a database can help you keep track of the various tables and their contents, making it easier to find and access specific data. This will also help you to manage the tables in your database, such as renaming them, deleting them, or modifying their structure.
This guide will elaborate on how users can list (show) tables in MySQL database while covering these aspects.
The above explanation is in the following sections.
Launch MySQL, View & Select Database
In all Linux distros, MySQL is already installed as a default package, and there’s no need to install it can be launched in any Linux terminal using this command.
$ sudo mysql -u root -p
As seen in the above image, after executing the command, it asks for a password which is by default set to blank (which means just press Enter) unless you’ve changed the password.
Now, use this command to select the database you wish to list tables of.
> use Database_Name
The database (testDB) is now selected, and we’d list its tables in the next section.
Showing Tables in a MySQL Database
Listing the tables in MySQL Database; there are a few variations but let’s start with the basics and then move on to the advanced ones.
The “SHOW TABLES” is a MySQL command that displays the list of all tables in the currently selected database; it is used like this.
> SHOW TABLES;
SHOW FULL TABLES
The “SHOW FULL TABLES” command is used in this format to see the full details of the Tables, including the type in the currently selected database.
> SHOW FULL TABLES;
If you don’t want to select Database before Listing the Tables, use this command.
> SHOW TABLES FROM Database_Name;
SHOW TABLES Using a Pattern
You can filter the Tables from the selected Database by using the ‘LIKE’ keyword as in this format.
> SHOW TABLES LIKE ‘Table_Name’;
Listing (Showing) Tables in a MySQL Database Without logging in to MySQL Shell
To list the Tables of the currently selected Database without using the MySQL Shell, use this command in this format.
$ sudo mysql -u user -p -e 'SHOW TABLES FROM Database_Name;'
These methods can be used to list tables in MySQL database.
Listing tables in a MySQL database can assist with organization and management, as well as troubleshooting and auditing. It allows you to view and track the tables in the database and their contents, making it easier to access and modify them as needed. In this article, we have discussed how you can list tables in MySQL Database.