Mysql-- view the database, table occupied by disk size

1 , the query all of the databases take up disk space
 the SELECT  
TABLE_SCHEMA, 
concat ( TRUNCATE ( SUM (data_length) / 1024 / 1024 , 2 ), ' MB ' ) AS data_size, 
concat ( TRUNCATE ( SUM (Index_length) / 1024 / 1024 , 2 ) , ' MB ' ) AS index_size
 from information_schema.tables
 Group  by the TABLE_SCHEMA
 the ORDER  bYData_Size desc ; 

2 , query a single database for all tables disk consumption size
 SELECT  
TABLE_NAME, 
the concat ( TRUNCATE (the data_length / 1024 / 1024 , 2 ), ' MB ' ) AS Data_Size, 
the concat ( TRUNCATE (Index_length / 1024 / 1024 , 2 ), ' MB ' ) AS index_size
 from information_schema.tables 
 WHERE the TABLE_SCHEMA =  ' xinyar_erp '
Group  by TABLE_NAME
 Order  by the data_length desc ; 

. 3 , using the command optimize 
optimize Table tb_report_inventory; 
time use longer need to wait. 

Note: When you optimize execution table will be locked, so do not use during peak hours. Do not use frequently, once a month is enough

 

Guess you like

Origin www.cnblogs.com/linjiqin/p/11446855.html