Most of the time we need information about our tables in a DB, so can check which table is getting bigger in size, or bigger in number of rows or records.
So here is a simple query to get all these information
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "databasename"
Just change “databasename” with your DB name.
If you want to get information just for a table, you can specify your table in query just like this
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "databasename" AND table_name = "yourtablenamehere"
Replace “yourtalbenamehere” with your table name.
There can be a satuation where you want information of more than a one table so query will be
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "databasename" AND table_name IN ('table_1', 'table_2', 'table_3');