数据库information_schema 中 TABLES 表的部分字段说明:table_schema(数据库名),TABLE_NAME (数据表名),data_length( 数据容量 ),index_length( 索引容量 ), table_rows ( 记录数 )
查看所有数据库容量大小
SELECT table_schema "Data Base Name", sum(data_length + index_length) / 1024 / 1024 "Data Base Size in MB", sum(data_free) / 1024 / 1024 "Free Space in MB" FROM information_schema. TABLES GROUP BY table_schema;
查看指定库的每个表容量大小
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 = 'mysql';
查看指定库中的指定表容量大小
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 = 'mysql' AND TABLE_NAME = "user";