Languages
[Edit]
EN

MySQL - get table size (in MB)

0 points
Created by:
Keisha-Acosta
380

In this article, we would like to show you how to get table size in MySQL.

Quick solution:

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

Note:

Replace only the database_name and table_name from the last 2 lines of code.

Practical example

Let's say we have the following database:

MySQL - example data used to get table size
MySQL - example data used to get table size

What interests us will be the size of the users table shown in the image above. We want to get it with a query.

Query:

SELECT 
    TABLE_NAME AS `Table`, 
    ROUND(((data_length + index_length) / 1024 / 1024), 3) `Size (in MB)` 
FROM information_schema.TABLES 
WHERE table_schema = "dirask"
    AND TABLE_NAME = "users";

Result:

MySQL - get table size using query - result
MySQL - get table size using query - result

Related posts

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join