Query to Get the Size of a Table in MySQL Database

a minute read

we can execute a query that will list all tables in a specific database along with the disk space (size) of each.

We can list all the tables along with each table size (disk space) by using a query.

SELECT table_name AS Table, ROUND(((data_length + index_length) / 1024 / 1024), 2) Size (MB) FROM information_schema.TABLES WHERE table_schema = “$Database_Name”;

Query to get list the size of every table in every database, with of the order of size:

SELECT
table_schema as
DatabaseName,
table_name AS
TableName,
round(((data_length + index_length) / 1024 / 1024), 2)
Size in MB
FROM information_schema.TableName
ORDER BY (data_length + index_length) DESC;

Query to get size of all databases

SELECT table_schema “Data Base Name”, SUM( data_length + index_length) / 1024 / 1024
“Data Base Size in MB” FROM information_schema.TABLES GROUP BY table_schema ;

    Facebook Twitter LinkedIn Telegram Whatsapp

    Related Posts:

    Below Mysql query is very useful to Get list of column name from table with its datatype. You can get list of all the tables name and all the fields count with help of this query. PHP Mysql Query In below query just change <–YoursDatabaseName–> to your d...
    If you looking for “How to get the number of rows about to get deleted.Please try small tricks to avoid unwanted data deletion. You can use SELECT  to get the number of rows about to get deleted. PHP Mysql Query By this query we check  the number of the delete...
    How to get second highest or nth maximum salary of an Employee table is one of the most frequently asked Mysql/SQL interview question. PHP Mysql Query Suppose we have the following simple database table called Employee that has 3 columns named Employee ID,Empl...