列出MariaDB数据库中所有视图的4种方法
以下是使用 SQL 或命令行列出 MariaDB 数据库中视图的四种方法。
命令SHOW TABLES
该命令列出给定数据库中的非表、序列和视图。我们可以使用子句将其缩小到视图。SHOW TABLES``TEMPORARY``WHERE
我们还可以使用 themodifier 返回显示类型的第二列:FULL
SHOW FULL TABLES
WHERE Table_Type LIKE 'VIEW';
结果:
+——————–+————+ | Tables_in_pethouse | Table_type | +——————–+————+ | vownercount | VIEW | | vpetcount | VIEW | | vpetsowners | VIEW | | vpetstypes | VIEW | | vpettypecount | VIEW | +——————–+————+
省略子句将返回所有类型:WHERE
SHOW FULL TABLES;
结果:
+——————–+————+ | Tables_in_pethouse | Table_type | +——————–+————+ | Owners | BASE TABLE | | PetTypes | BASE TABLE | | Pets | BASE TABLE | | vownercount | VIEW | | vpetcount | VIEW | | vpetsowners | VIEW | | vpetstypes | VIEW | | vpettypecount | VIEW | +——————–+————+
命令SHOW TABLE STATUS
命令类似于命令,但提供有关每个(非)表的更广泛信息。SHOW TABLE STATUS``SHOW TABLES``TEMPORARY
例:
SHOW TABLE STATUS;
结果:
+—————+——–+———+————+——+—————-+————-+—————–+————–+———–+—————-+———————+————-+————+——————–+———-+—————-+———+——————+———–+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | Max_index_length | Temporary | +—————+——–+———+————+——+—————-+————-+—————–+————–+———–+—————-+———————+————-+————+——————–+———-+—————-+———+——————+———–+ | Owners | InnoDB | 10 | Dynamic | 6 | 2730 | 16384 | 0 | 0 | 0 | NULL | 2021-03-30 09:10:36 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | PetTypes | InnoDB | 10 | Dynamic | 4 | 4096 | 16384 | 0 | 0 | 0 | NULL | 2021-03-30 09:10:36 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | Pets | InnoDB | 10 | Dynamic | 8 | 2048 | 16384 | 0 | 32768 | 0 | NULL | 2021-04-01 15:42:43 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | vownercount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetcount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetsowners | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetstypes | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpettypecount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | +—————+——–+———+————+——+—————-+————-+—————–+————–+———–+—————-+———————+————-+————+——————–+———-+—————-+———+——————+———–+
它还接受 aandclause,以防您想缩小结果范围。WHERE``LIKE
该表information_schema.TABLES
我们还可以查询表:information_schema.TABLES
SELECT
TABLE_SCHEMA,
TABLE_NAME,
TABLE_TYPE
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA LIKE 'pethouse' AND TABLE_TYPE LIKE 'VIEW';
结果:
+————–+—————+————+ | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | +————–+—————+————+ | PetHouse | vpettypecount | VIEW | | PetHouse | vpetstypes | VIEW | | PetHouse | vownercount | VIEW | | PetHouse | vpetcount | VIEW | | PetHouse | vpetsowners | VIEW | +————–+—————+————+
查询此内容而不按以下方式筛选结果将返回所有数据库中的视图。同样,在不筛选的情况下查询它也会返回所有表类型。TABLE_SCHEMA``TABLE_TYPE
客户mariadb-show
另一种方法是使用实用程序。mariadb-show
要使用此选项,请打开命令行提示符/终端窗口并运行以下命令(替换为您感兴趣的数据库):pethouse
mariadb-show pethouse;
结果:
+—————+ | Tables | +—————+ | Owners | | PetTypes | | Pets | | vownercount | | vpetcount | | vpetsowners | | vpetstypes | | vpettypecount | +—————+
这将返回视图和表。
输出仅显示您具有某些权限的数据库、表或列的名称。
如果未给出数据库,则显示所有匹配的数据库。如果未给出表,则显示数据库中所有匹配的表。如果未给出列,则显示表中所有匹配的列和列类型。
客户端也可以按以下方式运行:mysqlshow
mysqlshow pethouse;
该实用程序接受相当多的选项,例如(以便您可以传递用户名),(以便您可以传递密码)等。--user``--password
有关选项的完整列表,请参阅MariaDB 的文档。