Languages
[Edit]
EN

MySQL - get table size (in MB)

0 points
Created by:
Dirask Community
6240

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

MySQL - Problems

MySQL - get table size (in MB)
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