MySQL disable all triggers

36,467

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:

Query:

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

Triggers:

IF @disable_triggers IS NULL THEN
    // Do something use as the trigger isn't disabled.
END IF;
Share:
36,467
user810430
Author by

user810430

Updated on July 18, 2022

Comments

  • user810430
    user810430 almost 2 years

    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'
    

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