| by Arround The Web | No comments

How to Display Tables in a MySQL Database?

MySQL is one of the most efficient freely available databases having a user-friendly interface. It is a well-known DBMS because of its fast speed. Sometimes, users need to manage all databases. It is a more crucial process for the user as a database administrator to keep a close eye on all the modifications and processes in all database objects. More specifically, listing tables is essential when users have several databases that contain multiple tables.

This write-up will talk about:

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:

mysql -u root -p

Step 3: Display Databases

Then, to list all the existing databases, use the “SHOW” command and “DATABASES” option:

SHOW DATABASES;

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:

USE mariadb;

Step 5: View All Tables

After that, display all tables of the current database by utilizing the “SHOW” command with the “TABLE” option:

SHOW TABLES;

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:

SHOW FULL TABLES;

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:

SHOW TABLES FROM mariadb;

Another way to get the table details of any database without moving to it is using the “IN” clause:

SHOW TABLES IN mariadb;

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:

SHOW TABLES FROM mariadb LIKE '%db';

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:

SHOW TABLES FROM mariadb LIKE 'm%';

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.

Share Button

Source: linuxhint.com

Leave a Reply