【问题标题】:How can I know the database size of specific database in MYSQL?如何知道 MYSQL 中特定数据库的数据库大小?
【发布时间】:2019-11-23 06:45:05
【问题描述】:

我有一个名为“电话簿”的数据库。它包含 10 多个数据量适中的表。
现在我想知道使用 MySQL 查询的这个“电话簿”数据库的数据库大小。
我该怎么做?

【问题讨论】:

标签: mysql database size


【解决方案1】:

试试这个,它以 MB 为单位提供指定数据库的大小,

确保您指定DB_NAME

    SELECT table_schema ,
    ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
    FROM information_schema.tables  WHERE table_schema='DB_NAME'
    GROUP BY table_schema ;  

希望这会对您有所帮助! .

【讨论】:

  • 感谢@taha 的快速回复,这是我想要的答案。
【解决方案2】:

以下查询可以在表格视图中单独显示所有数据库的大小:

SELECT table_schema 'DB_NAME',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "以 MB 为单位的数据库大小"
FROM information_schema.tables
GROUP BY table_schema;

以下查询只能显示特定数据库的大小:

选择表模式,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "以 MB 为单位的数据库大小"
FROM information_schema.tables WHERE table_schema='DB_NAME'
GROUP BY table_schema ;

以下查询可以显示特定数据库的总表、总表行、DB 大小:

选择
TABLE_SCHEMA AS DB_Name,
计数(TABLE_SCHEMA)作为 Total_Tables,
SUM(TABLE_ROWS) 作为 Total_Tables_Row,
ROUND(sum(data_length + index_length)/1024/1024) AS "数据库大小 (MB)",
ROUND(sum( data_free )/ 1024 / 1024) AS "可用空间 (MB)"
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'DB_NAME'
GROUP BY TABLE_SCHEMA ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    • 2021-12-26
    • 2013-12-09
    相关资源
    最近更新 更多