John C John C - 4 months ago 41
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!


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';