How to query table and index size in MySQL

Source: Internet
Author: User

Querying MySQL table size and index size can be achieved through the tables table in the system library INFORMATION_SCHEMA.

Some of the fields used in this table are:

Table_schema: Database name
TABLE_NAME: Table name
Engine: the storage engine used
Tables_rows: Number of record lines
Data_length: Table Size
Index_length: Index size

1, you can query the database data row number, table space, index space, as below, replace [database name] with your own database name.

SELECT Table_schema as ' library name ',
CONCAT (ROUND (table_rows/10000, 2), ' million rows ') as ' number of rows ',
CONCAT (ROUND (SUM (data_length)/(1024*1024*1024), 2), ' GB ') as ' table space ',
CONCAT (ROUND (SUM (index_length)/(1024*1024*1024), 2), ' GB ') as ' index space ',
CONCAT (ROUND (SUM (data_length+index_length)/(1024*1024*1024), 2), ' GB ') as ' total space '
From INFORMATION_SCHEMA. TABLES WHERE table_schema = [database name];

2, of course, can not summarize, query the situation of the table under analysis, such as, the [database name] to replace your own database name can be.

SELECT table_name as ' table name ',
CONCAT (ROUND (table_rows/10000, 2), ' million rows ') as ' number of rows ',
CONCAT (ROUND (data_length/(1024*1024*1024), 2), ' GB ') as ' table space ',
CONCAT (ROUND (index_length/(1024*1024*1024), 2), ' GB ') as ' index space ',
CONCAT (ROUND ((data_length+index_length)/(1024*1024*1024), 2), ' GB ') as ' total space '
From INFORMATION_SCHEMA. TABLES WHERE table_schema = [database name] ORDER by Table_rows DESC;

How to query table and index size in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.