The number of records in MySQL that view all the tables in the database

Source: Internet
Author: User
Tags mysql version

If you are using a MySQL version of 5.0 or more, you can get it by querying the tables in the INFORMATION_SCHEMA library, which uses table_rows to record the number of rows in the table. For example, to view the number of records for all tables in the library TestDB:

The code is as follows Copy Code

Use INFORMATION_SCHEMA;

Select Table_name,table_rows from tables
where Table_schema = ' TestDB '
ORDER BY table_rows Desc;

It should be noted, however, that for InnoDB tables, the Table_rows row count is only a ballpark estimate.

Another way is to use the tables of the INFORMATION_SCHEMA library to stitch up a single SQL statement, such as:

  code is as follows copy code

Use Information_schema;

Select concat (
    ' select ',
    table_name,
    ' ", Count (*) from ',
    table_schema,
    '. ',
    table_name,
    ' UNION ALL
] from tables
where table_schema= ' TestDB ';

Record the number of records in MySQL that view all tables:

Table_schema: Database name
TABLE_NAME: Table name

ENGINE: the storage engine used
Tables_rows: Number of records

Data_length: The result of data size is in bytes, except 1024 is K, except 1048576 (=1024*1024) is M
Index_length: Index size

The code is as follows Copy Code
Use INFORMATION_SCHEMA;

Select Table_schema,table_name,table_rows from the tables order by table_rows Desc;


To view the specified database size:

The code is as follows Copy Code
SELECT sum (data_length) +sum (index_length) from INFORMATION_SCHEMA. TABLES where

Table_schema= ' database name ';

The resulting result is in bytes, except that 1024 is K, except 1048576 (=1024*1024) is M

Related Article

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.