John C John C - 3 days ago 4
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

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

SELECT option_value
 FROM `database1`.`table1`
  WHERE ...
UNION
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';
Comments