【MySQL】查看表的信息相关命令

文章目录

【免责声明】文章仅供学习交流,观点代表个人,与任何公司无关。
编辑|SQL和数据库技术(ID:SQLplusDB)

【MySQL】查看表的信息相关命令

在MySQL中,可以使用以下语句来查看表的信息:

  • SHOW TABLES; 查看数据库中的所有表
  • DESCRIBE 表名; 查看表的结构和字段信息
  • SHOW CREATE TABLE 表名; 查看创建表的完整SQL语句
  • SHOW TABLE STATUS LIKE '表名'; 查看表的详细信息,包括行数、大小等
  • information_schema.innodb_tables 表的信息
  • information_schema.innodb_tablespaces 表空间信息

查看表的信息相关命令例

例:

clike 复制代码
mysql> show tables;
+-------------------------------+
| Tables_in_testdb              |
+-------------------------------+
| sales_table                   |
| test                          |
| test_file_pertable            |
| test_file_pertable_tablespace |
| test_t1                       |
| yourTableName                 |
+-------------------------------+
6 rows in set (0.07 sec)

mysql> desc test;
+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| a     | int  | YES  |     | NULL    |       |
+-------+------+------+-----+---------+-------+
1 row in set (0.01 sec)

mysql>

mysql> SHOW CREATE TABLE test;
+-------+-----------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                    |
+-------+-----------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE `test` (
  `a` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

mysql> SHOW TABLE STATUS LIKE 'test';
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| 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 |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| test | InnoDB |      10 | Dynamic    |    0 |              0 |       16384 |               0 |            0 |         0 |           NULL | 2023-12-11 23:00:01 | NULL        | NULL       | utf8mb4_0900_ai_ci |     NULL |                |         |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> select * from information_schema.innodb_tables where NAME  like '%test'\G
*************************** 1. row ***************************
          TABLE_ID: 1425
              NAME: testdb/test
              FLAG: 33
            N_COLS: 4
             SPACE: 79
        ROW_FORMAT: Dynamic
     ZIP_PAGE_SIZE: 0
        SPACE_TYPE: Single
      INSTANT_COLS: 0
TOTAL_ROW_VERSIONS: 0
1 row in set (0.00 sec)

mysql>
mysql>  select * from
    ->  information_schema.innodb_tablespaces t
    ->  join information_schema.innodb_datafiles d
    ->  on t.SPACE=d.SPACE
    ->  where t.NAME  like '%test'\G
*************************** 1. row ***************************
          SPACE: 79
           NAME: testdb/test
           FLAG: 16417
     ROW_FORMAT: Dynamic
      PAGE_SIZE: 16384
  ZIP_PAGE_SIZE: 0
     SPACE_TYPE: Single
  FS_BLOCK_SIZE: 4096
      FILE_SIZE: 114688
 ALLOCATED_SIZE: 114688
AUTOEXTEND_SIZE: 0
 SERVER_VERSION: 8.0.35
  SPACE_VERSION: 1
     ENCRYPTION: N
          STATE: normal
          SPACE: 0x3739
           PATH: ./testdb/test.ibd
1 row in set (0.04 sec)
相关推荐
锐策4 小时前
〔 MySQL 〕数据库基础
数据库·mysql
日月星宿~5 小时前
【MySQL】summary
数据库·mysql
希忘auto6 小时前
详解MySQL安装
java·mysql
运维佬7 小时前
在 MySQL 8.0 中,SSL 解密失败,在使用 SSL 加密连接时出现了问题
mysql·adb·ssl
Runing_WoNiu7 小时前
MySQL与Oracle对比及区别
数据库·mysql·oracle
天道有情战天下7 小时前
mysql锁机制详解
数据库·mysql
CodingBrother7 小时前
MySQL 中单列索引与联合索引分析
数据库·mysql
布川ku子8 小时前
[2024最新] java八股文实用版(附带原理)---Mysql篇
java·mysql·面试
晴天飛 雪9 小时前
Spring Boot MySQL 分库分表
spring boot·后端·mysql
yc_xym9 小时前
【MySQL】MySQL基础知识复习(上)
数据库·mysql