文章目录
【免责声明】文章仅供学习交流,观点代表个人,与任何公司无关。
编辑|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)