John C John C - 1 year ago 96
MySQL Question

How do I search multiple databases at once?

I have imported many different databases into my wamp local host. It uses phpmyadmin and I am wondering if there is an easy way to search for let's say an email address from every table in every database at once, or tables I choose but from different databases. Is there a php script I can use that is similar to leaked source that could act like a search engine for the databases I have on my local host? Any help will be greatly appreciated!

Answer Source

As @Prasanna mentioned above, you can use UNION across the tables:

SELECT option_value
 FROM `database1`.`table1`
  WHERE ...
SELECT option_value2
 FROM `database2`.`table2`
  WHERE ..;

OR you can do something like below, if you're searching within a specific table and schema:

SELECT table_schema 
FROM information_schema.columns 
WHERE table_name = 'table1' AND column_name = 'id';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download