我在DB导出时只有35000 of records
的数据库表我发现文件大小超过2 GB。
即使我的表架构也不包含任何BLOB类型的数据。有没有办法在MySQL中识别表行大小。
答案 0 :(得分:1)
如果我们先通过执行下一个查询的空表找出消耗的内存大小,该怎么办:
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
AND table_name = "your_table_name";
然后在表中插入几行数据,然后再次执行上述查询,并计算一条记录的差异和内存消耗的平均值。 例: 我有一张桌子:
create table returning_players
(
casino_id int not null,
game_id int not null,
returning_players_count int null,
primary key (casino_id, game_id)
);
DROP PROCEDURE IF EXISTS query;
CREATE procedure query()
BEGIN
declare counter int(20) default 0;
LABEL:
LOOP
IF counter >= 1000000 THEN
LEAVE LABEL;
END IF;
INSERT INTO returning_players VALUES(counter, 45, 5475);
set counter = counter + 1;
END LOOP LABEL;
END;
CALL query();
答案 1 :(得分:0)
您可以使用此查询来显示表的大小(尽管您需要先替换变量):
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";