Run same query across multiple databases?

chowell's profile image chowell posted 11 months ago in General Permalink

Is it possible to run the same query across multiple databases?

Here's my use case. I have many databases with the same schema. I would like to see how many rows each has in its 'applications' table. So I want to run select count(*) from applications; across every database.

Does anyone know of a way to do that?

TIA!

ansgar's profile image ansgar posted 11 months ago Permalink

You cannot tell MySQL to run a single query on different databases. You can of course write a batch of queries in HeidiSQL and run these per F9:

SELECT COUNT(*) FROM db1.applications;
SELECT COUNT(*) FROM db2.applications;
...

You will get one result tab per query:

Description

chowell's profile image chowell posted 11 months ago Permalink

Yeah... that's what I figured. I was just hoping that maybe there was a lesser known feature of heidisql where I could select multiple databases to run my query against.

Thanks though!

ansgar's profile image ansgar posted 11 months ago Permalink

I just recall there is a feature request for exactly what you ask: see issue #1242

chowell's profile image chowell posted 11 months ago Permalink

yes, that would be amazing.

PS. Thank you for a wonderful product.

Please login to leave a reply, or register at first.