KB Article #151941

MySQL: finding out the size of each table in the embedded database

Problem

How can we find out the size of each table in ST's MySQL database?


Resolution

1. Connect to the MySQL database as described in the respective KB: for Linux/UNIX refer to KB 178322; for Windows refer to KB 178144.


2. Execute the query


SELECT CONCAT(table_schema, '.', table_name),
      CONCAT(ROUND(table_rows / 1000, 2), 'K') rows_size,
      CONCAT(ROUND(data_length / ( 1024 * 1024 ), 2), 'M') DATA,
      CONCAT(ROUND(index_length / ( 1024 * 1024 ), 2), 'M') idx,
      CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 ), 2), 'M') total_size,
      ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
WHERE table_schema='st'
ORDER BY data_length + index_length DESC;