「MySQL」- 获取库的大小

在 MySQL 中,如何获取特定数据库(或特定表)所占用的磁盘空间的大小?

统计库大小 | Database Size

How to get size of mysql database?

在通常情况下,数据表与数据索引会占用磁盘空间(其他部分可以忽略):

// 统计 Databse 大小

SELECT table_schema AS "DB Name",
        ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS "DBinMB"
FROM information_schema.tables
GROUP BY table_schema
ORDER BY DBinMB DESC 
LIMIT 30;

统计表大小 | Table Size

How to get the size of a table in MySQL

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = "bookstore"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;