SHOW DATABASESSHOW DATABASES

列出与选择性提供的正则表达式模式匹配的数据库。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. SCHEMASDATABASES 的使用可互换,这意味着它们是相同的。The usage of SCHEMAS and DATABASES are interchangeable and mean the same thing.

语法Syntax

SHOW { DATABASES | SCHEMAS } [ LIKE regex_pattern ]

参数Parameters

  • regex_patternregex_pattern

    用于筛选语句结果的正则表达式模式。A regular expression pattern that is used to filter the results of the statement. 除了 `and|`` 字符,模式的工作方式类似于正则表达式。 Except for `_and|`` character, the pattern works like a regular expression.

    • 只有 * 则匹配 0 个或多个字符,``|` 用于分隔多个不同的正则表达式,其中任何一个表达式都可以匹配。* 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

-- Create database. Assumes a database named `default` already exists in
-- the system.
CREATE DATABASE payroll_db;
CREATE DATABASE payments_db;

-- Lists all the databases.
SHOW DATABASES;
+------------+
|databaseName|
+------------+
|     default|
| payments_db|
|  payroll_db|
+------------+

-- Lists databases with name starting with string pattern `pay`
SHOW DATABASES LIKE 'pay*';
+------------+
|databaseName|
+------------+
| payments_db|
|  payroll_db|
+------------+

-- Lists all databases. Keywords SCHEMAS and DATABASES are interchangeable.
SHOW SCHEMAS;
+------------+
|databaseName|
+------------+
|     default|
| payments_db|
|  payroll_db|
+------------+