【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)
相关推荐
哲Zheᗜe༘2 小时前
了解学习MySQL数据库基础
数据库·学习·mysql
咋吃都不胖lyh2 小时前
MySQL 多表查询中,联合查询(UNION) 和子查询
mysql·数据分析
先鱼鲨生3 小时前
【MySQL】认识数据库以及MySQL安装
数据库·mysql
周杰伦_Jay4 小时前
【终端使用MySQL】MySQL 数据库核心操作全解析:从入门到性能优化
数据库·mysql·性能优化
-雷阵雨-6 小时前
MySQL——数据库入门指南
数据库·mysql
就叫飞六吧6 小时前
DataX适合全量同步和简单的增量场景
mysql
xhbh6668 小时前
【实战避坑】MySQL自增主键(AUTO_INCREMENT)全解:从锁机制、间隙问题到分库分表替代方案
android·数据库·mysql·mysql自增主键
程序员三明治12 小时前
【MyBatis从入门到入土】告别JDBC原始时代:零基础MyBatis极速上手指南
数据库·mysql·mybatis·jdbc·数据持久化·数据
知其然亦知其所以然12 小时前
面试官一开口就问:“你了解MySQL水平分区吗?”我当场差点懵了……
后端·mysql·面试
咖啡Beans12 小时前
MySQL的JSON_函数总结
mysql