MySQL query table and index size method MySQL query table and index size method

MySQL query table and index size method

 

  MySQL query size of the table and index size can be achieved by a system library information_schema in TABLES Table.

The table used some fields:

TABLE_SCHEMA: database name
TABLE_NAME: table
storage engine used: ENGINE
TABLES_ROWS: Record number of rows
DATA_LENGTH: table size
INDEX_LENGTH: index size

 

1, you can query the number of rows of data in the database, table space, index space, following the [database name] replace it with your own database name.

SELECT TABLE_SCHEMA AS 'library name',
CONCAT (ROUND (TABLE_ROWS / 10000, 2), 'million lines') AS 'rows',
CONCAT (ROUND (SUM (DATA_LENGTH) / (1024 * 1024 * 1024), 2), 'GB') AS 'tablespace',
CONCAT (the ROUND (the SUM (Index_length) / (1024 * 1024 * 1024), 2), 'GB') AS 'index space',
CONCAT (the ROUND (the SUM (DATA_LENGTH + Index_length) / (1024 * 1024 * 1024) , 2), 'GB') AS ' total space'
the FROM information_schema.tables the TABLE_SCHEMA the WHERE = [database name];

 

2, of course, can not be aggregated, query the case of each table were analyzed as follows, the [database name] replace it with your own database name.

SELECT TABLE_NAME AS 'table name',
CONCAT (ROUND (TABLE_ROWS / 10000, 2), 'million lines') AS 'rows',
CONCAT (ROUND (DATA_LENGTH / (1024 * 1024 * 1024), 2), 'GB' ) AS 'tablespace',
CONCAT (the ROUND (Index_length / (1024 * 1024 * 1024), 2), 'GB') AS 'index space',
CONCAT (the ROUND ((DATA_LENGTH + Index_length) / (1024 * 1024 * 1024 ), 2), 'GB' ) AS ' total space'
the FROM information_schema.tables the TABLE_SCHEMA the WHERE = [database name] ORDER BY TABLE_ROWS DESC;

 

  MySQL query size of the table and index size can be achieved by a system library information_schema in TABLES Table.

The table used some fields:

TABLE_SCHEMA: database name
TABLE_NAME: table
storage engine used: ENGINE
TABLES_ROWS: Record number of rows
DATA_LENGTH: table size
INDEX_LENGTH: index size

 

1, you can query the number of rows of data in the database, table space, index space, following the [database name] replace it with your own database name.

SELECT TABLE_SCHEMA AS 'library name',
CONCAT (ROUND (TABLE_ROWS / 10000, 2), 'million lines') AS 'rows',
CONCAT (ROUND (SUM (DATA_LENGTH) / (1024 * 1024 * 1024), 2), 'GB') AS 'tablespace',
CONCAT (the ROUND (the SUM (Index_length) / (1024 * 1024 * 1024), 2), 'GB') AS 'index space',
CONCAT (the ROUND (the SUM (DATA_LENGTH + Index_length) / (1024 * 1024 * 1024) , 2), 'GB') AS ' total space'
the FROM information_schema.tables the TABLE_SCHEMA the WHERE = [database name];

 

2, of course, can not be aggregated, query the case of each table were analyzed as follows, the [database name] replace it with your own database name.

SELECT TABLE_NAME AS 'table name',
CONCAT (ROUND (TABLE_ROWS / 10000, 2), 'million lines') AS 'rows',
CONCAT (ROUND (DATA_LENGTH / (1024 * 1024 * 1024), 2), 'GB' ) AS 'tablespace',
CONCAT (the ROUND (Index_length / (1024 * 1024 * 1024), 2), 'GB') AS 'index space',
CONCAT (the ROUND ((DATA_LENGTH + Index_length) / (1024 * 1024 * 1024 ), 2), 'GB' ) AS ' total space'
the FROM information_schema.tables the TABLE_SCHEMA the WHERE = [database name] ORDER BY TABLE_ROWS DESC;

 

Guess you like

Origin www.cnblogs.com/swarb/p/11363557.html