You are on page 1of 2

SELECT ROUND(SUM(data_length+index_length)/1024/1024)

AS total_mb,
ROUND(SUM(data_length)/1024/1024) AS data_mb,
ROUND(SUM(index_length)/1024/1024) AS index_mb
FROM INFORMATION_SCHEMA.tables;

SELECT ROUND(SUM(data_length+index_length)/1024/1024/1024)
AS total_gb,
ROUND(SUM(data_length)/1024/1024/1024) AS data_gb,
ROUND(SUM(index_length)/1024/1024/1024) AS index_gb
FROM INFORMATION_SCHEMA.tables;

Audit your database size: In MB

SELECT table_schema, engine,


ROUND(SUM(data_length+index_length)/1024/1024) AS total_mb,
ROUND(SUM(data_length)/1024/1024) AS data_mb,
ROUND(SUM(index_length)/1024/1024) AS index_mb,
COUNT(*) AS tables
FROM information_schema.tables
GROUP BY table_schema, engine
ORDER BY 3 DESC;

In GB:

SELECT table_schema, engine,


ROUND(SUM(data_length+index_length)/1024/1024/1024) AS total_gb,
ROUND(SUM(data_length)/1024/1024/1024) AS data_gb,
ROUND(SUM(index_length)/1024/1024) AS index_mb,
COUNT(*) AS tables
FROM information_schema.tables
GROUP BY table_schema, engine
ORDER BY 3 DESC;

Table Size in GB : specify the database and table name.

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024/1024), 2) `Size in GB`
FROM information_schema.TABLES
WHERE table_schema = "clarity_production"
AND table_name = "inquiries";

In GB:

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024/1024), 2) `Size in GB`
FROM information_schema.TABLES
WHERE table_schema = "crowd"

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024/1024), 2) `Size in GB`
FROM information_schema.TABLES
WHERE table_schema = "jiradb"
In MB:

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "crowd";

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "jiradb";

SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024/1024), 2) `Size in GB`
FROM information_schema.TABLES
WHERE table_schema = "srvinfodb";

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

You might also like