欢迎投稿

今日深度:

如何检查数据库各个Database和Table的大小?,

如何检查数据库各个Database和Table的大小?,


查看database大小

如下命令会显示各Database大小(以MB计算)。

SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema

结果如下:

| Database           | Size (MB)    |
+--------------------+--------------+
| http_certs         | 941.79687500 |
| information_schema |   0.15625000 |
| mysql              |   2.39560223 |
| performance_schema |   0.00000000 |
| sys                |   0.01562500 |
+--------------------+--------------+

查看某个特定table大小

将下面命令中的$DB_NAME$TABLE_NAME替换为要查询的database和table名即可。

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

查看全部table的大小

下面的命令由大到小列出每一个数据库中每一个表的大小。

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;

www.htsjk.Com true http://www.htsjk.com/teradata/33417.html NewsArticle 如何检查数据库各个Database和Table的大小?, 查看database大小 如下命令会显示各Database大小(以MB计算)。 SELECT table_schema AS "Database" , SUM ( data_length + index_length ) / 1024 / 1024 AS "Size (MB)" F...
相关文章
    暂无相关文章
评论暂时关闭