全部產品
Search
文件中心

:SHOW

更新時間:Nov 06, 2024

您可以通過SHOW語句查看資料庫相關資訊,例如資料庫列表、資料庫中的表以及表中的列或索引等。

SHOW DATABASES

查看當前叢集中的資料庫。

文法

SHOW DATABASES;            

樣本

SHOW DATABASES;

返回結果如下:

+--------------------+
| Database           |
+--------------------+
| adb_test           |
| MYSQL              |
| adb_demo           |
| INFORMATION_SCHEMA |
+--------------------+

SHOW TABLES

查看使用者當前資料庫中的表。

文法

SHOW TABLES [IN db_name];          

樣本

SHOW TABLES IN adb_demo;

返回結果如下:

+--------------------+
| Tables_in_adb_demo |
+--------------------+
| customer           |
| json_test          |
+--------------------+

SHOW COLUMNS

查看錶的列資訊。

文法

SHOW COLUMNS IN db_name.table_name;        

樣本

SHOW COLUMNS IN adb_demo.customer;

返回結果如下:

+---------+---------+------+------+---------+-------+
| Field   | Type    | Null | Key  | Default | Extra |
+---------+---------+------+------+---------+-------+
| id      | int     | NO   | PRI  | NULL    |       |
| name    | varchar | YES  |      | NULL    |       |
| address | varchar | YES  |      | NULL    |       |
| gender  | boolean | YES  |      | NULL    |       |
+---------+---------+------+------+---------+-------+

SHOW CREATE TABLE

查看錶的建表語句。

文法

SHOW CREATE TABLE db_name.table_name;          

樣本

SHOW CREATE TABLE adb_demo.customer;

返回結果如下:

+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                    |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| customer | Create Table `customer` (
 `id` int NOT NULL,
 `name` varchar(50),
 `address` varchar(80),
 `gender` boolean,
 primary key (`id`)
) DISTRIBUTED BY HASH(`id`) INDEX_ALL='Y' STORAGE_POLICY='HOT' BLOCK_SIZE=8192 |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

SHOW GRANTS

查看使用者的許可權。

文法

SHOW GRANTS [FOR 'username'@'hostname'];

其中,username為使用者名稱,hostname為主機名稱或主機IP。

樣本

  • 查看目前使用者的許可權,無需指定使用者名稱和主機。

    SHOW GRANTS;

    返回結果如下:

    +---------------------------------------------------------+
    | Grants for adb_acc@%                                    |
    +---------------------------------------------------------+
    | GRANT ALL ON `*`.`*` TO 'adb_acc'@'%' WITH GRANT OPTION |
    +---------------------------------------------------------+
  • 查看指定使用者的許可權。

    SHOW GRANTS FOR 'test'@'%';

    返回結果如下:

    +---------------------------------------------------------+
    | Grants for  test@%                                      |
    +---------------------------------------------------------+
    | GRANT ALL ON `*`.`*` TO 'adb'@'%' WITH GRANT OPTION     |
    +---------------------------------------------------------+

SHOW INDEXES

查看錶的索引資訊。

文法

SHOW INDEXES FROM db_name.table_name;  

樣本

SHOW INDEXES FROM adb_demo.json_test;

返回結果如下,其中Key_name即為索引名:

+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table     | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| json_test |          1 | id_0_idx |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| json_test |          1 | vj_idx   |            1 | vj          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+