What is the SHOW DATABASES Statement in MySQL and Why Do We Use It?
When you want to view the list of available databases on the MySQL server, you type the SHOW DATABASES statement.
The SHOW DATABASES statement is used to display the names of databases that are available on the MySQL server.
Syntax:
SHOW DATABASES;
Example:
SHOW DATABASES;
Output:
After executing the SHOW DATABASES statement, MySQL displays the list of available databases on the server.
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | PersonDB | | testdb | +--------------------+
How the SHOW DATABASES Statement Works Internally
When you execute the SHOW DATABASES statement, the command is sent to the MySQL server. The server checks the available databases and retrieves their names. After collecting the database information, MySQL displays the list of available databases to the user.
The SHOW DATABASES statement only displays database names. It does not create, delete, or modify any database or data.
Flowchart:
👤 User | ▼ ⌨️ SHOW DATABASES; | ▼ 🖥️ MySQL Server | ▼ 🔍 Check Available Databases | ┌───────┴───────┐ ▼ ▼ ✅ Found ❌ Not Found | | ▼ ▼ 📁 Retrieve ⚠️ Error Database List Message | ▼ 📄 Display Available Databases
Precautions While Using SHOW DATABASES Statement:
- You must connect to the MySQL server before executing the SHOW DATABASES statement.
- The displayed database list depends on the user's permissions.
- The SHOW DATABASES statement only displays available databases; it does not select or activate any database.
- Make sure that you are connected to the correct MySQL server before checking databases.
How to Use the SHOW DATABASES Statement in MySQL: Step-by-Step Guide
If you use the SHOW DATABASES statement in MySQL, you first need to connect to the MySQL server. After connecting, you can execute the SHOW DATABASES statement to view the list of available databases. The complete process is as follows:
Step 1: You connect to the MySQL server by using the MySQL login command.
mysql -u username -p
Step 2: You type the SHOW DATABASES statement to view the list of available databases.
SHOW DATABASES;
Step 3: MySQL displays the list of available databases on the server.
Step 4: After viewing the database list, you can perform further database operations according to your requirement.
Note:
- The SHOW DATABASES statement displays the list of available databases.
- The database list shown by MySQL depends on the user's access permissions.
- The SHOW DATABASES statement does not create, delete, or modify any database.












