How to Display Tables in a MySQL Database?
This write-up will talk about:
- How to Display Tables in a MySQL Server?
- How to Display Tables of Another MySQL Database?
- How to Display Tables of Another Database in a MySQL Using “LIKE” Clause?
How to Display Tables in a MySQL Server?
Check out the following instructions to display the tables in a MySQL database.
Step 1: Redirect to Windows Terminal
At first, open the “Command Prompt” through the Startup menu:
Step 2: Access MySQL Database
Use the provided command for connecting the terminal to the MySQL server by specifying the username and providing the password:
Step 3: Display Databases
Then, to list all the existing databases, use the “SHOW” command and “DATABASES” option:
From the below-stated list of databases, we have selected the “mariadb” database for further process:
Step 4: Change Database
Next, run the “USE” command with the particular database name and switch to it:
Step 5: View All Tables
After that, display all tables of the current database by utilizing the “SHOW” command with the “TABLE” option:
According to the given output, our database contains only one table named “mariadb”:
Step 6: View Full Tables
To view the list of tables with their type, provided command can be used:
How to Display Tables of Another MySQL Database?
You can also view the tables details of any database without changing them through the “SHOW TABLES FROM <database>” command:
Another way to get the table details of any database without moving to it is using the “IN” clause:
How to Display Tables of Another Database in a MySQL Using “LIKE” Clause?
The “LIKE” clause is also the best choice for those who don’t know the table name or forget the full name:
Here, the “%” symbol before the “db” is used to display all the databases ending with these letters:
If you only know the first letter of the database name, then you can use the following command:
That’s it! You have learned different ways to view the tables in the MySQL database.
Conclusion
To view the tables in MySQL database, different SQL statements can be used according to the user’s desire, such as the “SHOW TABLES” statement, the “SHOW TABLES FROM <database>” statement, or the “SHOW TABLES FROM <database> LIKE <‘%variable%’>” statement. This guide illustrated several SQL statements to display tables in a MySQL database.
Source: linuxhint.com