Listing databases in MySQL or MariaDB provides a quick inventory of schemas available to an account before running migrations, granting privileges, or pointing an application at the right server.

The server treats “database” and “schema” as synonyms and stores the names in its internal data dictionary. The mysql client (or mariadb on some systems) sends SQL to the server, and SHOW DATABASES returns a result set that is filtered by privileges unless the account has the global SHOW DATABASES privilege.

System schemas such as information_schema, mysql, performance_schema, and sometimes sys often appear alongside application schemas. Connection details (host, port, authentication plugin, and TLS requirements) determine whether the client can log in, so listing databases is most reliable after a known-good login using an account intended for administration or automation.

Steps to list databases in MySQL or MariaDB:

  1. Open a terminal session that can reach the database server.
  2. Connect to the server using the mysql client.
    $ mysql --host db.example.net --port 3306 --user dbadmin --password
    Enter password: ********
    mysql>

    Avoid --password=secret because credentials can be exposed via process listings and shell history.

    For a local Unix socket connection, omit –host and –port:

    $ mysql --user dbadmin --password
  3. List databases visible to the current account.
    mysql> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | app                |
    | reporting          |
    +--------------------+
    6 rows in set (0.00 sec)

    The result is privilege-scoped unless the account has the global SHOW DATABASES privilege.

    In the interactive client, terminate statements with ; to execute them.

  4. Filter database names using LIKE when matching a prefix or substring.
    mysql> SHOW DATABASES LIKE 'app%';
    +----------+
    | Database |
    +----------+
    | app      |
    +----------+
    1 row in set (0.00 sec)

    In LIKE patterns, '%' matches any length and '_' matches a single character.

  5. Exclude common system schemas using a WHERE clause to focus on application databases.
    mysql> SHOW DATABASES WHERE `Database` NOT IN ('information_schema','mysql','performance_schema','sys');
    +-----------+
    | Database  |
    +-----------+
    | app       |
    | reporting |
    +-----------+
    2 rows in set (0.00 sec)
  6. Check for an exact database name by matching it with LIKE.
    mysql> SHOW DATABASES LIKE 'reporting';
    +-----------+
    | Database  |
    +-----------+
    | reporting |
    +-----------+
    1 row in set (0.00 sec)

    An empty result indicates the database name is not present or not visible to the account.

  7. Select a database to confirm basic access.
    mysql> USE reporting;
    Database changed

    An access error indicates missing privileges on the selected database.

  8. Confirm the selected database name from the server.
    mysql> SELECT DATABASE();
    +------------+
    | DATABASE() |
    +------------+
    | reporting  |
    +------------+
    1 row in set (0.00 sec)
  9. Exit the client session.
    mysql> exit
    Bye
Discuss the article:

Comment anonymously. Login not required.