Mysql statistical database, table data size

Mysql statistics database data size

When we need to know how much disk size the database occupies, we can query the capacity of the entire database through some SQL statements, or we can view the capacity occupied by the table separately.

# Query according to conditions, print out the data size of the query table (print information one by one)

use information_schema

select TABLE_NAME, concat(truncate(DATA_LENGTH/1024/1024,2), 'MB') as data_size,concat(truncate(INDEX_LENGTH/1024/1024,2), 'MB') as index_size from TABLES where TABLE_NAME like '%20210131%' order by data_length desc; 

# Query according to conditions, print out the data size of the query table (accumulate all)

select TABLE_NAME, concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data_size,concat(round(sum(INDEX_LENGTH/1024/1024),2), 'MB') as index_size from TABLES where TABLE_NAME like '%20210131%' ;

#If there is no where, query all

Description:

TABLE_SCHEMA: database name

TABLE_NAME: table name

DATA_LENGTH: data size

INDEX_LENGTH: Index size

ORDER BY: sort according to the size of the query

 

Guess you like

Origin blog.csdn.net/ganices/article/details/113524628