Skip to main content
added 4 characters in body
Source Link
Gustav
  • 418
  • 1
  • 4
  • 9

Not a single answer or comment even mentions a possible overhead of the database tables and doesn't take this into account in the SQL query.

This is the most common mistake when somebody asks: "How big is my database X?". And after getting the wrong! total size, asks: "But then why there's so little space left on the partition/disk where database data is located?".

This is how you get actual total size of the database, replace [DATEBASE_NAME] with your database name:

SELECT `TABLE_SCHEMA` AS "Database", format_bytesFORMAT_BYTES(SUM(`DATA_LENGTH` + `INDEX_LENGTH` + `DATA_FREE`)) AS "Total Size" FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '[DATEBASE_NAME]';

* when using MariaDB instead of MySQLversion <11.8, then prepend function format_bytesname FORMAT_BYTES with "sys.": sys.format_bytes .

Result:

+----------------+------------+
| Database       | Total Size |
+----------------+------------+
| v3             | 3.56 GiB   |
+----------------+------------+

Not a single answer or comment even mentions a possible overhead of the database tables and doesn't take this into account in the SQL query.

This is the most common mistake when somebody asks: "How big is my database X?". And after getting the wrong! total size, asks: "But then why there's so little space left on the partition/disk where database data is located?".

This is how you get actual total size of the database, replace [DATEBASE_NAME] with your database name:

SELECT `TABLE_SCHEMA` AS "Database", format_bytes(SUM(`DATA_LENGTH` + `INDEX_LENGTH` + `DATA_FREE`)) AS "Total Size" FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '[DATEBASE_NAME]';

* when using MariaDB instead of MySQL, then prepend function format_bytes with "sys.": sys.format_bytes .

Result:

+----------------+------------+
| Database       | Total Size |
+----------------+------------+
| v3             | 3.56 GiB   |
+----------------+------------+

Not a single answer or comment even mentions a possible overhead of the database tables and doesn't take this into account in the SQL query.

This is the most common mistake when somebody asks: "How big is my database X?". And after getting the wrong! total size, asks: "But then why there's so little space left on the partition/disk where database data is located?".

This is how you get actual total size of the database, replace [DATEBASE_NAME] with your database name:

SELECT `TABLE_SCHEMA` AS "Database", FORMAT_BYTES(SUM(`DATA_LENGTH` + `INDEX_LENGTH` + `DATA_FREE`)) AS "Total Size" FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '[DATEBASE_NAME]';

* when using MariaDB version <11.8, then prepend function name FORMAT_BYTES with "sys.": sys.format_bytes .

Result:

+----------------+------------+
| Database       | Total Size |
+----------------+------------+
| v3             | 3.56 GiB   |
+----------------+------------+
Source Link
Gustav
  • 418
  • 1
  • 4
  • 9

Not a single answer or comment even mentions a possible overhead of the database tables and doesn't take this into account in the SQL query.

This is the most common mistake when somebody asks: "How big is my database X?". And after getting the wrong! total size, asks: "But then why there's so little space left on the partition/disk where database data is located?".

This is how you get actual total size of the database, replace [DATEBASE_NAME] with your database name:

SELECT `TABLE_SCHEMA` AS "Database", format_bytes(SUM(`DATA_LENGTH` + `INDEX_LENGTH` + `DATA_FREE`)) AS "Total Size" FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '[DATEBASE_NAME]';

* when using MariaDB instead of MySQL, then prepend function format_bytes with "sys.": sys.format_bytes .

Result:

+----------------+------------+
| Database       | Total Size |
+----------------+------------+
| v3             | 3.56 GiB   |
+----------------+------------+