how to get mysql table size in GB

后端 未结 6 608
终归单人心
终归单人心 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:20

    To calculate the size of a row, use length() method.

    For example:

    MariaDB [db]> select id,length(row_to_calcsize) from tablename order by id desc limit 2\G
    *************************** 1. row ***************************
         id: 501
    length(row_to_calcsize): 2192911
    *************************** 2. row ***************************
         id: 500
    length(row_to_calcsize): 51657
    2 rows in set (0.00 sec)
    
    MariaDB [db]> 
    

    To calculate size in GB, just divide it 3 times per 1024

    length(row_to_calcsize)/1024/1024/1024
    

提交回复
热议问题