The SHOW DATABASES statement is used to display the databases that are available to the current MySQL user. It is one of the basic commands used when exploring and managing a MySQL server.
SHOW DATABASES is a MySQL statement used to list databases accessible to the current user.
SHOW DATABASES;
The result is displayed as a list of database names.
The basic syntax is:
SHOW DATABASES;
The statement is normally terminated with a semicolon.
Run the following command:
SHOW DATABASES;
You may see results similar to:
information_schema
mysql
performance_schema
sys
school
library
The exact list depends on your MySQL installation and user permissions.
MySQL installations commonly contain system databases used internally by MySQL.
Examples can include:
These databases serve different administrative and metadata purposes.
Developers can create their own databases for applications.
CREATE DATABASE school;
CREATE DATABASE library;
After creation, these databases can appear when you run:
SHOW DATABASES;
CREATE DATABASE school;
SHOW DATABASES;
The result can include school along with other databases accessible to the current user.
You can run SHOW DATABASES from the MySQL command-line client.
mysql> SHOW DATABASES;
MySQL returns the available database names in a text-based result.
You can also execute the command in MySQL Workbench.
SHOW DATABASES;
The result appears in the SQL Editor's result area.
A common workflow is to first display databases and then select one.
SHOW DATABASES;
USE school;
SHOW DATABASES lists available databases, while USE selects one for the current session.
SHOW DATABASES lists databases, but it does not tell you which one is currently selected.
Use:
SELECT DATABASE();
You can create multiple databases and then view them using SHOW DATABASES.
CREATE DATABASE school;
CREATE DATABASE library;
CREATE DATABASE company;
SHOW DATABASES;
The command returns a column containing database names.
Database
--------
school
library
company
The exact formatting may differ depending on the client you use.
The databases displayed by SHOW DATABASES depend on the privileges and visibility available to the current MySQL user.
A user with limited permissions may see fewer databases than an administrator.
Suppose a user connects to MySQL:
mysql -u student -p
After logging in, the user can run:
SHOW DATABASES;
The returned list depends on the privileges of that account.
| Command | Purpose |
|---|---|
| SHOW DATABASES; | Displays accessible databases |
| SHOW TABLES; | Displays tables in the selected database |
| Command | Purpose |
|---|---|
| SHOW DATABASES; | Lists databases |
| USE school; | Selects the school database |
These commands perform different tasks.
You can use both commands together when setting up a new application.
CREATE DATABASE IF NOT EXISTS school;
SHOW DATABASES;
This creates the database if necessary and then displays accessible databases.
After dropping a database, you can use SHOW DATABASES to verify the current list.
DROP DATABASE school;
SHOW DATABASES;
Warning: DROP DATABASE removes the database and its objects. Use it carefully.
MySQL also provides a form that can be used to display databases matching a pattern.
SHOW DATABASES LIKE 'school%';
This can help find database names that match a specific pattern.
The LIKE pattern can be used with SHOW DATABASES.
For example:
SHOW DATABASES LIKE '%school%';
This looks for database names containing school in the pattern.
MySQL also supports SHOW SCHEMAS as a synonym for SHOW DATABASES.
SHOW SCHEMAS;
It can be used to display the databases accessible to the current user.
1. Connect to MySQL
2. Run SHOW DATABASES
3. Find the required database
4. Use the database
5. Run SHOW TABLES
6. Work with the tables
CREATE DATABASE school;
SHOW DATABASES;
USE school;
SHOW TABLES;
This is a simple workflow for creating and exploring a school database.
CREATE DATABASE library;
SHOW DATABASES;
USE library;
SHOW TABLES;
The database can then be used to create tables for books, members, and transactions.
SHOW DATABASES is simple, but you may still face connection-related problems.
Database applications normally use a selected database in their connection configuration.
Administrators or development tools can use SHOW DATABASES to inspect available databases, depending on the account's permissions.
SHOW DATABASES;
When developing multiple projects on the same MySQL server, SHOW DATABASES can help you identify available databases.
school_db
library_db
company_db
inventory_db
You can then select the required database with USE.
Remember the difference between these commands:
SHOW DATABASES;
USE school;
SHOW TABLES;
CREATE DATABASE IF NOT EXISTS school;
CREATE DATABASE IF NOT EXISTS library;
SHOW DATABASES;
USE school;
SELECT DATABASE();
SHOW TABLES;
This example creates two databases, displays the database list, selects the school database, checks the current database, and displays its tables.
Suppose a MySQL server contains several project databases. You can discover and select the required database as follows:
SHOW DATABASES;
SHOW DATABASES LIKE '%library%';
USE library_db;
SELECT DATABASE();
SHOW TABLES;
This workflow helps you find an available database, select it, verify the selection, and then explore its tables.
Question: Which command is used to display databases accessible to the current MySQL user?