Skip to main content

Generate the table size from a Database.

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

If you don’t care about all tables in the database and only want the size of a particular table, you can simply add AND TABLE_NAME = "your_table_name" to the WHERE clause. Here we only want information about the book table:

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

Leave a Reply

Your email address will not be published. Required fields are marked *