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:

table_schema as
table_name AS
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 Export MySQL data to Excel in PHP ?” This script will used to export data into .xls format from mysql database.You need to just copy this code and update database connection details. Below code will export mysql data into excel (.xls format) with ever...