我可以运行这个查询来获得MySQL数据库中所有表的大小:
show table status from myDatabaseName;
我希望有人能帮助我理解结果。我在找尺寸最大的桌子。
我应该看哪一列?
我可以运行这个查询来获得MySQL数据库中所有表的大小:
show table status from myDatabaseName;
我希望有人能帮助我理解结果。我在找尺寸最大的桌子。
我应该看哪一列?
当前回答
最后计算数据库的总大小:
(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"
)
UNION ALL
(SELECT
'TOTAL:',
SUM(round(((data_length + index_length) / 1024 / 1024), 2) )
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
)
其他回答
SELECT TABLE_NAME AS "Table Name",
table_rows AS "Quant of Rows", ROUND( (
data_length + index_length
) /1024, 2 ) AS "Total Size Kb"
FROM information_schema.TABLES
WHERE information_schema.TABLES.table_schema = 'YOUR SCHEMA NAME/DATABASE NAME HERE'
LIMIT 0 , 30
您可以从“information_schema”-> SCHEMATA表->“SCHEMA_NAME”列中获取模式名称
额外的 你可以得到mysql数据库的大小如下。
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema
ORDER BY `DB Size in MB` DESC;
结果
DB Name | DB Size in MB
mydatabase_wrdp 39.1
information_schema 0.0
你可以在这里得到更多的细节。
SELECT TABLE_NAME AS table_name,
table_rows AS QuantofRows,
ROUND((data_length + index_length) /1024, 2 ) AS total_size_kb
FROM information_schema.TABLES
WHERE information_schema.TABLES.table_schema = 'db'
ORDER BY (data_length + index_length) DESC;
以上2个都是在mysql上测试的
改编自ChapMic的回答,以满足我的特殊需要。
只指定数据库名称,然后按降序对所有表进行排序——在所选数据库中从最大到最小的表。只需要替换1个变量=数据库名。
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) AS `size`
FROM information_schema.TABLES
WHERE table_schema = "YOUR_DATABASE_NAME_HERE"
ORDER BY size DESC;
尝试以下shell命令(将DB_NAME替换为您的数据库名称):
mysql -uroot <<<"SELECT table_name AS 'Tables', round((data_length + index_length) / 1024 / 1024), 2)Size in MB FROM information_schematable WHERE table_schema = \"DB_NAME\" ORDER BY (data_length + index_length) DESC;"|头
对于Drupal/drush解决方案,检查下面的示例脚本,它将显示正在使用的最大表:
#!/bin/sh
DB_NAME=$(drush status --fields=db-name --field-labels=0 | tr -d '\r\n ')
drush sqlq "SELECT table_name AS 'Tables', round(((data_length + index_length) / 1024 / 1024), 2) 'Size in MB' FROM information_schema.TABLES WHERE table_schema = \"${DB_NAME}\" ORDER BY (data_length + index_length) DESC;" | head -n20
这只是一个供以后参考的说明。所有答案都依赖于I_S.TABLES。例如,如果你在表中有blob字段,它不会告诉你正确的大小。LOB页存储在外部页中,因此不计入聚集索引。 事实上有一个注释:
对于NDB表,该语句的输出显示适当的值 AVG_ROW_LENGTH和DATA_LENGTH列,例外 没有考虑到BLOB列。
我发现InnoDB也是如此。
我已经创建了社区Bug相同。