MYSQL - count number of rows in each table

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.


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. 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

Tags:

Mysql

Sql