Mysql – Query other database’s INFORMATION_SCHEMA tables

database-designinformation-schemaMySQL

I have a shared database that stores procedures for all the other databases on the same server. This helps maintain one instance of a procedure rather than copying it across all databases. As long as I prepend DBName to all my tables, i.e. SELECT * FROM DBName.Table, I've been able to successfully have a shared repository for procedures.

However, I've run into an instance where I need to reference INFORMATION_SCHEMA tables, but the shared database only has tables for that database. Is there a concept of querying INFORMATION_SCHEMA on another database?

I'd like to do something like this, but it doesn't work:

SELECT * FROM [DBName].INFORMATION_SCHEMA.TABLES

Best Answer

I think this does what you need:

CREATE
    DEFINER = root
    PROCEDURE ...
    SECURITY INVOKER   -- This limits what the proc can do to what the user is GRANTed
    BEGIN ... END

See http://dev.mysql.com/doc/refman/5.6/en/create-procedure.html