SHOW DATABASES

Description

Lists the databases that match an optionally supplied regular expression pattern. If no pattern is supplied then the command lists all the databases in the system. Please note that the usage of SCHEMAS and DATABASES are interchangeable and mean the same thing.

Syntax

  1. SHOW { DATABASES | SCHEMAS } [ LIKE regex_pattern ]

Parameters

  • regex_pattern

    Specifies a regular expression pattern that is used to filter the results of the statement.

    • Except for * and | character, the pattern works like a regular expression.
    • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
    • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.

Examples

  1. -- Create database. Assumes a database named `default` already exists in
  2. -- the system.
  3. CREATE DATABASE payroll_db;
  4. CREATE DATABASE payments_db;
  5. -- Lists all the databases.
  6. SHOW DATABASES;
  7. +------------+
  8. |databaseName|
  9. +------------+
  10. | default|
  11. | payments_db|
  12. | payroll_db|
  13. +------------+
  14. -- Lists databases with name starting with string pattern `pay`
  15. SHOW DATABASES LIKE 'pay*';
  16. +------------+
  17. |databaseName|
  18. +------------+
  19. | payments_db|
  20. | payroll_db|
  21. +------------+
  22. -- Lists all databases. Keywords SCHEMAS and DATABASES are interchangeable.
  23. SHOW SCHEMAS;
  24. +------------+
  25. |databaseName|
  26. +------------+
  27. | default|
  28. | payments_db|
  29. | payroll_db|
  30. +------------+