简体   繁体   English

MYSQL - 计算每个表中的行数

[英]MYSQL - count number of rows in each table

I would like to know how many rows are in each table in my database.我想知道我的数据库中每个表中有多少行。 I've come so far as to having我已经做到了

select count(*) _tablename_; 

However i would need to do that on each and every table - and there are a lot.但是,我需要在每张桌子上都这样做 - 而且有很多。 What would me the best way to get a print-out with the table name and it's row count?我用表名和行数打印输出的最佳方法是什么?

SELECT table_name, table_rows
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = '<your db>';

I also hope you realise there's an error in your query: it's missing a FROM .我也希望您意识到您的查询中有一个错误:它缺少一个FROM

This following query will return number of rows in each table but it doesn't seem to return exact value all the time以下查询将返回每个表中的行数,但它似乎并不总是返回精确值

SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<your db>';

TABLE_ROWS : The number of table rows in the partition. TABLE_ROWS :分区中的表行数。 For partitioned InnoDB tables, the row count given in the TABLE_ROWS column is only an estimated value used in SQL optimization, and may not always be exact... for more https://dev.mysql.com/doc/mysql-infoschema-excerpt/5.5/en/partitions-table.html对于分区的 InnoDB 表,TABLE_ROWS 列中给出的行数只是 SQL 优化中使用的估计值,可能并不总是准确的...更多https://dev.mysql.com/doc/mysql-infoschema-摘录/5.5/en/partitions-table.html

In addition to SQL queries by others, one can also use Workbench GUI to get the row-counts of each table.除了其他人的 SQL 查询外,还可以使用 Workbench GUI 来获取每个表的行数。 To do this, Launch Workbench -> Connect to Db -> right click Db and select "Schema Inspector" (as in Screenshot below - I have highlighted the "Rows" column):为此,启动 Workbench -> Connect to Db -> 右键单击​​ Db 并选择“Schema Inspector”(如下面的屏幕截图所示 - 我突出显示了“Rows”列):

在此处输入图片说明

HTH.哈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM