【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)
相关推荐
卓琢2 分钟前
(九)Shell 脚本(四):正则表达式、sed 和 awk 详解
linux·mysql·正则表达式
大拇指的约定2 小时前
数据库(MySQL):使用命令从零开始在Navicat创建一个数据库及其数据表(三),单表查询
数据库·mysql·oracle
银氨溶液3 小时前
MySql数据引擎InnoDB引起的锁问题
数据库·mysql·面试·求职
unix2linux5 小时前
Parade Series - SHA256
linux·python·mysql·shell
hefaxiang6 小时前
【MYSQL】mysql约束---自增长约束(auto_increment)
数据库·mysql
计算机学姐7 小时前
基于微信小程序的调查问卷管理系统
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
momo小菜pa17 小时前
【MySQL 06】表的增删查改
数据库·mysql
程序员大金20 小时前
基于SpringBoot+Vue+MySQL的装修公司管理系统
vue.js·spring boot·mysql
gorgor在码农20 小时前
Mysql 索引底层数据结构和算法
数据结构·数据库·mysql
-seventy-20 小时前
SQL语句 (MySQL)
sql·mysql