我可以查询某些行或列在 MySQL 中占用的磁盘空间大小吗?
可以,使用以下语法 −
select * from information_schema.tables where table_name=yourTableName;
我们首先创建一个表 −
mysql> create table DemoTable1600 -> ( -> StudentId int, -> StudentFirstName varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)
使用插入命令向表中插入一些记录 −
mysql> insert into DemoTable1600 values(100,'Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1600 values(101,'David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1600 values(102,'Carol'); Query OK, 1 row affected (0.19 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1600;
这将产生以下输出 −
+-----------+------------------+ | StudentId | StudentFirstName | +-----------+------------------+ | 100 | Bob | | 101 | David | | 102 | Carol | +-----------+------------------+ 3 rows in set (0.00 sec)
获取某些行或列占用的磁盘空间大小 −
mysql> select * from information_schema.tables where table_name='DemoTable1600';
这将产生以下输出
+---------------+--------------+---------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | +---------------+--------------+---------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+ | def | web | demotable1600 | BASE TABLE | InnoDB | 10 | Dynamic | 0 | 0 | 16384 | 0 | 0 | 0 | NULL | 2019-10-19 14:34:46 | NULL | NULL | utf8_unicode_ci | NULL | | | +---------------+--------------+---------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------------+ 1 row in set (0.00 sec)
广告