How to Show the List of Databases in MySQL?
In MySQL, you can view the list of all databases available on the server. This is useful when you need to check existing databases, verify successful database creation, or simply explore the available database structures.
In this tutorial, we will explain how to display the list of databases in MySQL using both the command-line interface (CLI) and MySQL Workbench.
Using the MySQL Command-Line Interface to SHOW DATABASES
The MySQL CLI provides a simple command to list all databases. Follow these steps:
Step 1: Connect to the MySQL Server
Open your terminal or command prompt and log in to the MySQL server using the following command:
mysql -u username -p
Replace username
with your MySQL username. Enter your password when prompted to establish the connection.
In this guide, we will login to the server as root (username is root
) as shown in the following screenshot.
Step 2: Show the List of Databases
Once logged in, execute the following SQL command to display all databases:
SHOW DATABASES;
This command will return a list of databases available on the server. For example:
Each row in the result represents a database. System databases like information_schema
, performance_schema
, and sys
are typically included by default.
Step 3: Exit the MySQL Shell
To exit the MySQL CLI, type the following command:
exit;
This will close your connection to the MySQL server.
Using MySQL Workbench to SHOW DATABASES
MySQL Workbench provides a graphical interface for viewing the list of databases. Follow these steps:
Step 1: Launch MySQL Workbench
Open MySQL Workbench on your system and connect to the MySQL server by selecting the appropriate connection from the home screen.
Step 2: View the List of Databases
After connecting, locate the “Schemas” panel on the left-hand side of the Workbench interface. This panel displays all available databases (schemas) on the connected server.
If the “Schemas” panel is not visible, click on the highlighted icon present in the top right corner.
Step 3: Execute SQL to List Databases
You can also run the SHOW DATABASES;
command in the Query Editor to display the list of databases. To do this:
1. Open a new Query tab.
2. Enter the command SHOW DATABASES;
.
3. Click on the execute button (lightning icon) to run the query.
The results will display in the output panel below.