我可以运行这个查询来获得MySQL数据库中所有表的大小:

show table status from myDatabaseName;

我希望有人能帮助我理解结果。我在找尺寸最大的桌子。

我应该看哪一列?


当前回答

如果你有ssh访问权限,你可能想简单地尝试du -hc /var/lib/mysql(或不同的datadir,在my.cnf中设置)。

其他回答

如果你有ssh访问权限,你可能想简单地尝试du -hc /var/lib/mysql(或不同的datadir,在my.cnf中设置)。

这应该在mysql中测试,而不是postgresql:

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; 

尝试以下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
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`, 
    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";

或者这个查询列出每个数据库中每个表的大小,最大的先:

SELECT 
     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;