List Databases in MySQL with SHOW DATABASES
List MySQL databases with SHOW DATABASES or from the command line. Learn why results vary by account privileges, filter names, and query schema metadata.
Use SHOW DATABASES to list database names visible to the current MySQL account. SHOW SCHEMAS is a synonym. The results depend on the account’s privileges and server settings, so a regular account may see fewer databases than an administrator.
List databases
Connect with a MySQL account that has the access you need, then run:
SHOW DATABASES;
You can also use the equivalent statement:
SHOW SCHEMAS;
To list databases directly from a shell, pass the statement to the MySQL command-line client with --execute (or -e):
mysql --user=app_user --password --execute='SHOW DATABASES;'
Replace app_user with an account that can connect to the server. With no password value supplied, --password prompts for it instead of placing the secret in the command or shell history. For a remote server, add the appropriate --host and --port options. See the MySQL --execute client option.
For example, a server might return:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sample_app |
| reporting_db |
| sakila |
| sys |
+--------------------+This output is illustrative. Actual database names depend on the server, and a user account may not see every database. Avoid using root for routine application work; use a dedicated account with only the privileges required.
MySQL normally shows database names for which the account has some privilege. If the server starts with --skip-show-database, the statement requires the global SHOW DATABASES privilege. Global privileges and partial revokes can also affect visibility. See the MySQL SHOW DATABASES reference for the complete rules.
Filter database names
Use LIKE to match a pattern:
SHOW DATABASES LIKE 'sample%';
To use a more complex condition, add a WHERE clause:
SHOW DATABASES WHERE `Database` <> 'mysql';
The result is still limited by the account’s database-visibility rules.
Query schema metadata
INFORMATION_SCHEMA.SCHEMATA provides schema names and metadata such as the default character set and collation:
SELECT schema_name, default_character_set_name, default_collation_name
FROM information_schema.schemata
WHERE schema_name = 'sample_app';
The view only shows schemas visible to the current account. Read the MySQL SCHEMATA reference for its columns and visibility behavior.