在开发中遇到一个问题,我要统计哪个表中的数据增长度快。于是就想要找出每个表的大小。
SELECT
CONCAT( table_schema, '.', table_name ) AS 'Table Name',
CONCAT( ROUND( table_rows / 1000000, 4 ), 'M' ) AS 'Number of Rows',
CONCAT( ROUND( data_length /( 1024 * 1024 ), 4 ), 'M' ) AS 'Data Size',
CONCAT( ROUND( index_length /( 1024 * 1024 ), 4 ), 'M' ) AS 'Index Size',
CONCAT( ROUND(( data_length + index_length )/( 1024 * 1024 ), 4 ), 'M' ) AS 'Total'
FROM
information_schema.TABLES
ORDER BY
total DESC;
这段代码是统计每个表的大小,是M为单位,如果需要其他单位再*1024或者少一个*1024。下图为统计之后的结果。