Mysql views the number of records of all tables in the database

Source: Internet
Author: User
Mysql uses selectcount (*) fromtable_name to query the total number of records in a table. What should I do if I want to quickly know the number of records of all tables in the database? If you use mysql 5.0 or later, you can query the tables Table in the information_schema database. This table uses table_rows to record the number of rows of the table. For example

Mysql uses select count (*) from table_name to query the total number of records of a table. What should I do if I want to quickly know the number of records of all tables in the database? If you use mysql 5.0 or later, you can query the tables Table in the information_schema database. This table uses table_rows to record the number of rows of the table. For example

Mysql uses select count (*) from table_name to query the total number of records of a table. What should I do if I want to quickly know the number of records of all tables in the database? If you use mysql 5.0 or later, you can query the tables Table in the information_schema database. This table uses table_rows to record the number of rows of the table. For example, to view the number of records of all tables in the database testdb:

use information_schema;select table_name,table_rows from tableswhere TABLE_SCHEMA = 'testdb'order by table_rows desc;

However, for InnoDB tables, table_rows row counts are only approximate estimates.

Another method is to concatenate an SQL statement using the tables Table of the information_schema database, for example:

use information_schema;select concat(    'select "',    TABLE_name,    '", count(*) from ',    TABLE_SCHEMA,    '.',    TABLE_name,    ' union all') from tableswhere TABLE_SCHEMA='testdb';

You just need to manually process the generated results, at least faster than spelling a table.

Original article address: mysql views the number of records of all tables in the database. Thank you for sharing it with the original author.

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.