在所有架构中安装
要获取架构列表,请使用show databases;。将此与-- use结合起来:
use schemaA;
-- use schemaB;
-- use schemaC;
create procedure ...
手动遍历模式,在继续操作时删除和取消注释use 子句,检查一切是否正常。在 MySQL Workbench 中,Ctrl+Shift+Enter 是您的朋友。
在架构子集中安装例程
通常您不想将存储的例程安装在服务器上的 all 模式中,而只能安装在 子集 中 --- 通常由模式集定义已经安装了一些特定的存储例程。然后,as discussed on SO,您可以使用这样的查询来获取相关架构的名称:
SELECT ROUTINE_SCHEMA FROM `information_schema`.`ROUTINES` where specific_name = 'MyRoutine';
验证
部署例程后,要验证它们是否存在,您可以使用如下查询:
SELECT distinct
r1.ROUTINE_SCHEMA,
case when r2.specific_name is not null then '' else '####' end as RoutineName1,
case when r3.specific_name is not null then '' else '####' end as RoutineName2,
case when r4.specific_name is not null then '' else '####' end as RoutineName3
FROM
`information_schema`.`ROUTINES` as r1
LEFT JOIN (select * from `information_schema`.`ROUTINES` where specific_name = 'RoutineName1') as r2 on r1.routine_schema = r2.routine_schema
LEFT JOIN (select * from `information_schema`.`ROUTINES` where specific_name = 'RoutineName2') as r3 on r1.routine_schema = r3.routine_schema
LEFT JOIN (select * from `information_schema`.`ROUTINES` where specific_name = 'RoutineName3') as r4 on r1.routine_schema = r4.routine_schema
where
r1.specific_name = 'FilteringRoutineName';
此查询将检查RoutineName1、RoutineName2 和RoutineName3 是否存在于您的服务器上具有例程FilteringRoutineName 的数据库模式中。如果缺少例程,则会用#### 标记。
当然,这只是检查例程是否存在。要验证它们的实现,您可能需要一个数据库差异工具(例如 MySQL Compare 或类似工具)。