如何获取MySQL数据库表的大小? [英] How to get the sizes of the tables of a MySQL database?

查看:226
本文介绍了如何获取MySQL数据库表的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can run this query to get the sizes of all tables in a MySQL database:

show table status from myDatabaseName;

我希望对理解结果有所帮助.我正在寻找尺寸最大的桌子.

I would like some help in understanding the results. I am looking for tables with the largest sizes.

我应该看哪一列?

推荐答案

您可以使用此查询显示表的大小(尽管您需要先替换变量):

You can use this query to show the size of a table (although you need to substitute the variables first):

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";

或此查询以列出每个数据库中每个表的大小,从大到大:

or this query to list the size of every table in every database, largest first:

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;

这篇关于如何获取MySQL数据库表的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆