MySQL Workbench – How to Store a Query for Various Schemas

MySQLmysql-workbench

We have multiple identical schemas. How can I store a query and easily apply it to any of multiple schemas? Bonus points for a drag & drop or point & click method of executing the query.

My first attempt was to set a variable for the schema, like this

SET @db = MySchema;

SELECT * from @db.mytable;

but I get Error Code: 1146. Table 'db.tagdescriptions' doesn't exist.

I'm using MySQL Workbench 6.3, connecting to MySQL Community Server (GPL) 5.6.19-log on Win64.

Best Answer

In addition to what Rick wrote:

If you just wanna have an ad hoc solution (not something you frequently use) you could also just have your query in the editor without a schema and sequentially make each of the schemas you want to process the default schema by double clicking on it's name in the schema tree. I.e. make first one default, run the query. Make the next one default and run the query, and so on.