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:
Listing MySQL databases is a common administrative task with several practical use cases. Here are the most common ones.
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.
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.
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;
You can also list all databases using the command line. There are three common methods for this.
mysql -h <host> -u <username> -p -e "SHOW DATABASES;"
In this syntax:
mysqlshow -u user -p
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.
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).
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.
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.
You can just as well access a MySQL server remotely and list the databases it contains using scripts.
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;"
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
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()
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.
bind-address = 0.0.0.0 or the server's IP in my.cnf or mysqld.cnf.
GRANT ALL ON *.* TO 'username'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
[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.
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!
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.
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.
In MySQL, SHOW DATABASES and SHOW SCHEMAS are functionally identical.
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.
Yes, you can view hidden or system databases in dbForge Studio, but your user must have sufficient privileges for that.
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.
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.
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.