One SQL to query the data size of all tables in the MySQL database

Recently, large tables need to be managed at work, so the first step is to count the data volume of each table in MySQL. Surely you can't do it for every table SELECT count(*) FROM table_name, the efficiency is too low. How to use one SQL statement to query the data volume of all tables?

  1. First query the database information:

    SHOW DATABASES;
    
  2. Then you can see that all libraries are included in the returned result, we can choose information_schema:

    USE information_schema;
    
  3. Execute the following statement:

    SELECT table_name, table_rows FROM tables ORDER BY table_rows DESC
    
  4. The amount of data in each table can be counted.

  5. The required SELECTcolumns and WHEREconditions can be dynamically adjusted~

renew

Overturned, if it is an InnoDB storage engine, you should not use this method. For details, see the different values ​​of count(*) in MySQL and table_rows in information_schema.tables

Guess you like

Origin blog.csdn.net/itigoitie/article/details/127929487