【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)
相关推荐
KELLENSHAW2 小时前
MySQL45讲 第三十七讲 什么时候会使用内部临时表?——阅读总结
数据库·mysql
四七伵2 小时前
MySQL外键类型与应用场景总结:优缺点一目了然
mysql
core5123 小时前
flink cdc各种数据库 jar下载地址
mysql·oracle·flink·jar·oceanbase·cdc
别致的影分身4 小时前
MySQL 常用程序介绍
数据库·mysql
HD2436088364 小时前
【mysql】id主键列乱了之后,重新排序(可根据日期顺序)
数据库·sql·mysql
qq_448941085 小时前
6、mysql的MHA故障切换
数据库·mysql
会飞的爱迪生5 小时前
mysql主从同步延迟原因分析
数据库·mysql
席万里5 小时前
InnoDB存储引擎【MySQL从放弃到入门】
数据库·mysql
lcx_defender5 小时前
【Docker】部署MySQL容器
mysql·docker·容器
木易小熙6 小时前
MySQL最左匹配原则是什么
数据库·mysql