Save Big on Cyber Monday! Up to 40% Off
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

List MySQL Databases: How to Use the SHOW DATABASES Command

Getting a list of MySQL databases that reside on a server may come in handy for various reasons. For example, developers will use it to explore the current environment, and DBAs will need it to carry out routine server maintenance.

In this article, you will get a comprehensive guide on how to show databases in MySQL and filter them according to certain criteria. Read on to find out about the following:

  • The syntax of SHOW DATABASES in MySQL
  • The SHOW SCHEMAS command to view MySQL databases
  • Permissions required to list all databases in MySQL
  • How to filter the database list
  • How to list all databases in MySQL from the command line
  • How to view databases in MySQL with a GUI tool

Common use cases for listing MySQL databases

Listing MySQL databases is a common administrative task with several practical use cases. Here are the most common ones.

  1. Database exploration and auditing, used to check what databases exist on a server. It helps understand what's hosted on a server you have just connected to, audit resource usage, or validate environment setups.
  2. Permission and access checks, used to verify which databases a user has access to. This is important for enforcing data security and confirming that access control policies are working correctly.
  3. Backup and recovery, where you need to determine which databases need to be backed up or restored. Since backup tools may require specific database names, listing them helps automate and validate these operations.
  4. Database development and testing may require developers to get lists of databases in order to prevent, for instance, accidental operations on production databases. Additionally, we can mention scripts that often include lists of databases to iterate over. With the said list always at hand, developers can easily apply schema updates across multiple databases or run consistency checks.
  5. Maintenance is yet another vital operation, which requires DBAs to identify old, unused, or temporary databases, and clean them up to free up space and improve performance. A quick way to see all databases will definitely be useful here.

How to get a list of databases with the MySQL SHOW DATABASES command

Run the following query to show all databases in MySQL:

SHOW DATABASES;

You can run this statement from the MySQL Command Line Client, MySQL Shell, or any GUI tool that supports SQL (for example, dbForge Studio for MySQL).

MySQL returns the results in a table with one column - Database. The databases are ordered in alphabetical order. The number of rows in the set is the number of databases.

MySQL Database Listing
Note
Unless you have the global SHOW DATABASES privilege, you will see only the databases you are permitted to see. You can also grant all privileges in MySQL for the required user so that they could view all the databases on a server.

MySQL SHOW DATABASES Syntax & Options

MySQL SHOW DATABASES

How to view MySQL databases with SHOW SCHEMAS

The SHOW SCHEMAS is an alternative MySQL command that helps get a list of existing databases on a server.

SHOW SCHEMAS;

Similarly to the MySQL SHOW DATABASES statement, SHOW SCHEMAS can be run from the MySQL Command Line Client, MySQL Shell, and dbForge Studio for MySQL.

The outputs returned by MySQL will be identical.

Show schemas

Filtering the database list using SHOW DATABASES LIKE

There might be a lot of databases on the server, and the list can be quite large. In this case, you may benefit from using the LIKE expression along with the MySQL SHOW DATABASES command:

SHOW {DATABASES | SCHEMAS}
[LIKE 'pattern' | WHERE expression]

Suppose, we need to get the list of all databases that start with 'S'. The query will look as follows:

SHOW DATABASES LIKE 's%';

And if we need to list all databases whose names are more than 7 characters long, we can run the following query:

SHOW DATABASES WHERE LENGTH(`Database`) > 7;
Show databases like

How to get a list of all databases in MySQL from the command line

You can also list all databases using the command line. There are three common methods for this.

  1. Open the Command Prompt and navigate to the bin folder of your MySQL Server installation directory. Then connect to the server using the mysql -u root -p command. Enter the password and run the SHOW DATABASES command.
  2. Open the Command Prompt, navigate to the bin folder of your MySQL Server installation directory, and run the query:
mysql -h <host> -u <username> -p -e "SHOW DATABASES;"

In this syntax:

  • -h is the IP address or domain of the remote MySQL server
  • -u is your MySQL username
  • -p will prompt you for the password
  • -e will execute SHOW DATABASES directly from the command line
  1. Alternatively, from the same bin folder of your MySQL Server installation directory, run the following query:
mysqlshow -u user -p

List databases in MySQL by information_schema

There is another popular way to show databases in MySQL - to query the required information directly from the schemata table of the MySQL information_schema database. To do that, execute a MySQL SELECT query.

For example, the following statement returns the same result as the SHOW DATABASES command.

SELECT schema_name
FROM information_schema.schemata;

And again, the query can be run from the MySQL Command Line Client, MySQL Shell, or dbForge Studio for MySQL.

Information schema

Display and manage MySQL database lists with dbForge Studio

dbForge Studio for MySQL is a universal all-in-one GUI tool bound to solve all possible database development, management, and administration tasks. With the Studio, you can work with MySQL and MariaDB databases in an intuitive, well-designed interface.

After you connect to the server, the databases that are hosted on it will be displayed in Database Explorer. To view tables, just expand the database and table nodes.

All the abovementioned commands work well from the Studio's integrated SQL Editor equipped with context-sensitive code completion and instant syntax validation.

More than that, dbForge Studio comes with a Security Manager that helps set up user accounts, their roles and privileges (including access to specific databases).

Display and manage MySQL database lists with dbForge Studio

SHOW DATABASE in MySQL: Useful tips and best practices

To find out which database is currently selected, use the following query:

SELECT DATABASE();

You can read more about this statement on the MySQL Select Database page. In dbForge Studio, the selected database will be shown in the menu ribbon. You can easily switch between the databases using the dropdown.

To see the tables from a selected database, run this query:

SHOW TABLES;

Also note that in dbForge Studio, database tables can be displayed by expanding nodes in Database Explorer.

Key interface elements

Why SHOW DATABASES might not display all databases

There are several reasons why the SHOW DATABASES command might not display all databases on your server. These reasons are mostly related to permissions, configuration settings, or server issues.

Reason #1. Insufficient permissions

Users can only see databases for which they have permissions. Thus, if you can't see certain databases, this might happen because you don't have the required permissions or privileges. To check your privileges, you can run the following command:

SHOW GRANTS FOR 'username'@'host';

In this command, username refers to your MySQL user, and host refers to the hostname or IP address from which you connect.

You can grant more permissions to your current user from a user with broader privileges, e.g., a root user.

Here is a brief recap of key user types with the databases they are permitted to access.

User Type Accessed databases Example output Notes
Administrator (root user) All databases on the server mysql, information_schema, test, app_db, etc. Full access, including system and user-created databases
Normal user Only databases that can be accessed according to the user's privileges app_db, reporting_db Hidden databases will not appear, even if they exist
Guest user or new user (no privileges) Nothing (or, in some cases, system databases) An empty set Requires GRANT permissions on at least one database to display any names
User with revoked access information_schema or nothing information_schema or an empty set May vary based on the skip_show_database setting

Reason #2. The skip_show_database option

If your MySQL has been started with the skip_show_database option, it may prevent you from seeing databases unless you have the SHOW DATABASES privilege granted explicitly.
To see whether this option is on, you can inspect the MySQL configuration file (my.cnf or my.ini) or check the command line options used to start MySQL.

Reason #3. Databases hidden by design

Some internal or temporary databases may not be listed by default depending on your MySQL version or configuration.

Listing databases remotely or using scripts

You can just as well access a MySQL server remotely and list the databases it contains using scripts.

Using the MySQL CLI

We have previously mentioned that SHOW DATABASES can be executed from the MySQL CLI as follows:

mysql -h <host> -u <username> -p -e "SHOW DATABASES;"

Using a bash script

You can also create a bash script (list_dbs.sh) like this:

#!/bin/bash

HOST="192.168.1.10"
USER="username"
PASS="password"

mysql -h "$HOST" -u "$USER" -p"$PASS" -e "SHOW DATABASES;"

Then make it executable:

chmod +x list_dbs.sh
./list_dbs.sh

Using Python with mysql-connector-python

First, install the connector:

pip install mysql-connector-python

The Python script for that will be as follows:

import mysql.connector

conn = mysql.connector.connect(
    host='192.168.1.10',
    user='username',
    password='password'
) 

cursor = conn.cursor()
cursor.execute("SHOW DATABASES")

for db in cursor:
    print(db[0])

cursor.close()
conn.close()

Tips for listing MySQL databases remotely

  1. Use the -h flag to specify the remote host. Here's what a command with the -h flag looks like:
mysql -h <remote_host> -u <username> -p -e "SHOW DATABASES;"

In this syntax, <remote_host> can be a hostname or IP address (e.g., mysql.example.com or 192.168.1.100). Also note that if you omit -h, the client will try to connect to the local socket.

  1. Make sure remote access to the server is enabled. Check whether your MySQL server is listening on a public IP (not just 127.0.0.1). You can set bind-address = 0.0.0.0 or the server's IP in my.cnf or mysqld.cnf.
  2. Get remote privileges for your user account. For instance, here's how a root user can grant remote access with all privileges:
GRANT ALL ON *.* TO 'username'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
  1. Store your credentials in the hidden my.cnf file. It is going to look like this:
[client]
user=<username>
password=<password>
host=<remote_host>

Now you can run the familiar SHOW DATABASES command in the following simple way:

mysql --defaults-file=~/.my.cnf -e "SHOW DATABASES;"

This method helps keep credentials out of the shell history and scripts.

Conclusion

The easiest way to see the list of databases in MySQL involves dbForge Studio for MySQL, one of the market today. It encompasses dozens of useful features that allow you to perform any database-related tasks: create a database in MySQL, back up a MySQL database, conduct MySQL performance monitoring and many, many more. However, a picture paints a thousand words, so we welcome you to download a FREE fully functional 30-day trial of dbForge Studio for MySQL and check it in action!

Frequently Asked Questions

How do I see hidden or skipped databases in MySQL?

Some databases may appear to be hidden or skipped for a few reasons, including permission restrictions, configuration settings, or specific filters.

1. To see all databases (if you have sufficient privileges), you should log in as a root user or a user with the SHOW DATABASES privilege.

The SHOW DATABASES privilege can be granted by a root user with the following command:

GRANT SHOW DATABASES ON *.* TO 'username'@'host'; FLUSH PRIVILEGES;

2. You can query the metadata to list all databases, even those hidden by SHOW DATABASES:

SELECT SCHEMA_NAME FROM information_schema.SCHEMATA;

This gives a more direct view of your MySQL server, regardless of permissions for the SHOW DATABASES command.

3. You can check the MySQL configuration file (my.cnf or my.ini) for the --skip-show-database or --skip-name-resolve options.

--skip-show-database disables SHOW DATABASES entirely for users without the SHOW DATABASES privilege.

--skip-name-resolve doesn't hide databases but disables DNS lookup; it is useful in some troubleshooting contexts.

Does MySQL SHOW DATABASES require admin privileges?

No, SHOW DATABASES does not strictly require admin privileges. A SHOW DATABASES privilege, granted to the user you are logged in under, will be enough to let you see the list of databases on your MySQL server.

What's the difference between SHOW DATABASES and SHOW SCHEMAS?

In MySQL, SHOW DATABASES and SHOW SCHEMAS are functionally identical.

What does skip_show_database do?

The skip_show_database option in MySQL is a security feature that restricts access to the SHOW DATABASES command. When it is enabled, users without the SHOW DATABASES privilege can only see the databases they have privileges on. This is the default behavior in newer MySQL versions.

Does dbForge Studio support viewing hidden or system databases?

Yes, you can view hidden or system databases in dbForge Studio, but your user must have sufficient privileges for that.

How to get a list of MySQL databases from dbForge Studio?

dbForge Studio has an integrated SQL Editor, which allows running all kinds of SQL queries against your database. Just run the SHOW DATABASES command and get the output right away.

Is there a visual Database Explorer in dbForge Studio?

dbForge Studio offers a convenient Database Explorer that helps you conveniently navigate across all database objects on your MySQL server. You can also perform a number of operations with those objects using the Explorer's context menu.

Can I export a list of all databases using dbForge Studio?

Yes, you can export the output of any query directly from the results grid of the Studio's SQL Editor. Simply click Export Data on the toolbar, select any of the available 14 file formats, and follow the wizard's instructions to export your database list to a file.

dbForge Edge

dbForge Studio for MySQL

The best MySQL GUI tool for effective DB development