SQL

How to View SQL Databases

February 28, 2023

This guide is part of the "Snippets" series. This series is focused on providing simple and accessible tutorials on various topics relating to development!


The SHOW DATABASES command is a SQL statement used to display a list of all the databases available on a database server. This command is specific to certain SQL database management systems, such as MySQL and PostgreSQL, and may not be supported by all systems.

When you execute the SHOW DATABASES command, the database server returns a list of all databases that the current user has permission to access. The result set typically includes the name of each database, and may also include other information such as the database size, creation date, or owner.

Here is an example of how to use the SHOW DATABASES command in MySQL:

SHOW DATABASES;

Executing this command will return a list of all databases available on the MySQL server. Note that you must have appropriate privileges to execute this command, and the specific syntax may vary slightly depending on the SQL database management system you are using.

Here are a few additional points that are relevant to the SHOW DATABASES command:

Permissions: The ability to execute the SHOW DATABASES command is controlled by the database server's access control system. In most database management systems, you must have appropriate permissions to view the list of databases. For example, in MySQL, you need the SHOW DATABASES privilege to execute this command.

Filtering: The SHOW DATABASES command returns a list of all databases available on the server, but you can filter the results to include only certain databases. For example, in MySQL, you can use the LIKE operator to filter the list of databases based on a pattern.

Here's an example:

SHOW DATABASES LIKE 'my_%';

This command would return a list of all databases whose names start with "my_" (such as "my_database" or "my_app").

Ordering: By default, the SHOW DATABASES command returns the list of databases in alphabetical order. However, you can specify a different ordering by using the ORDER BY clause.

Here's an example:

SHOW DATABASES ORDER BY size DESC;

This command would return the list of databases sorted by size in descending order.

System databases: In addition to user-created databases, most database management systems also include a number of system databases that are used for internal purposes. These databases are usually not included in the list returned by the SHOW DATABASES command. However, some database management systems provide a separate command for listing system databases, such as SHOW SCHEMAS in PostgreSQL.


You might also like

The latest from the blog