how to get mysql table size in GB

后端 未结 6 615
终归单人心
终归单人心 2020-12-09 04:43

Just ended up with calculating the size of MySQL table in GB with the following query.

SELECT (data_length+index_length)/power(1024,3) tablesize_gb FR

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 05:03

    To find table size we can use something like this..

    SELECT count(*) tables,
           concat(round(sum(table_rows)/1000000,2),'M') rows,
           concat(round(sum(data_length)/(1024*1024*1024),2),'G') data,
           concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
           concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
           round(sum(index_length)/sum(data_length),2) idxfrac
           FROM information_schema.TABLES
           WHERE  table_name like "%table-name%"
    

    Find the largest table in MYSQL Databases we can use something like this

    SELECT CONCAT(table_schema, '.', table_name),
           CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
           CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
           CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
           CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
           ROUND(index_length / data_length, 2)                                           idxfrac
    FROM   information_schema.TABLES
    ORDER  BY data_length + index_length DESC
    LIMIT  10
    

提交回复
热议问题