MySQL禁用所有触发器 [英] MySQL disable all triggers

查看:530
本文介绍了MySQL禁用所有触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了测试查询的正确性,我需要禁用db中的所有触发器. 我看到在information_schema中存在表TRIGGERS. 是否可以使用此表暂时禁用所有触发器? 例如.像:

For test correctness of query I need disable all triggers in db. I see that in information_schema exists table TRIGGERS. Is possible temporarily disable all triggers using this table? E.g. like:

update TRIGGERS set TRIGGERS_SCHEMA='myschema_new' 
where TRIGGERS_SCHEMA='myschema'

在完成所有测试后,返回所有触发器,例如:

and after finish all test return all triggers like:

update TRIGGERS set TRIGGERS_SCHEMA='myschema'
where TRIGGERS_SCHEMA='myschema_new'

这可能会损坏db还是在触发后将不起作用?我没有在文档中找到它.

May be this can corrupt db or after triggers will not works? I didn't found about it in documentation.

推荐答案

您不能直接禁用触发器,我也不建议您执行建议的操作,但是可以让触发器检查变量(在我的示例中)在执行触发器的内容之前,@disable_triggers以下的是NULL.例如:

You can't disable triggers directly and I wouldn't recommend doing what you're suggesting but you could have your trigger check if a variable (in my example below @disable_triggers) is NULL before executing the trigger's content. For example:

查询:

SET @disable_triggers = 1;
// Your update statement goes here.
SET @disable_triggers = NULL;

触发器:

IF @disable_triggers IS NULL THEN
    // Do something use as the trigger isn't disabled.
END IF;

这篇关于MySQL禁用所有触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆