嗨,大家有人知道如何估计一个MySQL表的大小? 我的意思是我打算对所有服务器上的所有mysql表进行备份,但是我想知道每个转储表有多大,而不需要进行物理转储。 有一些命令可以做到这一点? 我在Debian 6干杯上使用mysql 5.1
正如在这里看到的,你可以在你的数据库上运行这些查询(从页面上的评论中偷走,然后调整)。
SELECT table_schema 'database', concat( round( sum( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) size FROM information_schema.TABLES WHERE ENGINE=('MyISAM' || 'InnoDB' ) GROUP BY table_schema;
SELECT concat( table_schema, '.', table_name ) table_name, concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length, concat( round( index_length / ( 1024 *1024 ) , 2 ) , 'M' ) index_length, concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) total_size FROM information_schema.TABLES ORDER BY ( data_length + index_length ) DESC;
由于mysqldump是数据库的逻辑表示,因此只能find实际的数据。 索引永远不会存储在mysqldump中,但是表定义将决定如何填充索引。
由于写入mysqldump的内容很难为mysqldump选取确切的数字:
你可以看作是一个因素,只是data_lengths的总和:
SELECT SUM(data_length)/POWER(1024,2) TotalDB_MB FROM information_schema.tables;
通过数据库和总计查看总和:
SELECT table_schema,SUM(data_length)/POWER(1024,2) DB_MB FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','performance_schema','mysql') GROUP BY table_schema WITH ROLLUP;
要查看小计的每个表和数据库:
SELECT table_schema,table_name,SUM(data_length)/POWER(1024,2) DB_MB FROM information_schema.tables WHERE table_schema NOT IN ('information_schema','performance_schema','mysql') GROUP BY table_schema,table_name WITH ROLLUP;
您可以使用以下内容
POWER(1024,1)报告以KB为单位 POWER(1024,2)报告以MB为单位 POWER(1024,3)以GB POWER(1024,3)报告 POWER(1024,4)在TB中报告 POWER(1024,5)报告PB
你可以使用这个公式
一个mysqldump大小的最终公式
CharactersForSQLPerTable X NumberOfTables + Characters for "INSERT INTO tblname VALUES " + TotalDB_MB