Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding total number of rows of tables across multiple databases

Tags:

sql

mysql

count

I have 67 different databases and each database has more than one common table. One such table is company and I want to find total rows in that table from all the databases. How can I write a query to get total number of rows from all the databases?

like image 585
yogsma Avatar asked Nov 28 '25 08:11

yogsma


1 Answers

You can query the INFORMATION SCHEMA.

SELECT SUM(table_rows) FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'company'

You can use the ENGINE column in the table to see if you're counting on MyISAM tables (the table_rows will be correct then), or InnoDB (table_rows will be the estimate used by the optimizer)

If you have more than only the company table, you can GROUP BY tablename :)

like image 53
Konerak Avatar answered Nov 30 '25 22:11

Konerak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!