I want a trigger to fire only when UPDATEs are user-initiated (not me running updates from the MySQL command line).
What’s the ‘industry standard’ for achieving this? I have been trying unsuccessfully to detect a variable passed in with the query (i.e. @user_update=true), but without success. A colleague of mine suggested a way to do it would be to add a new column into the table containing the trigger: ‘fire_trigger’, for example. And fill this with ‘true’ when running the SQL from the code, and ensure that this is present in order for the trigger to fire.
Any help much appreciated!
Disable the trigger before doing command-line updates and re-enable it after.
But you’re doing this wrong, conceptually.
Why shouldn’t the trigger run when you use the command line? I Assume this is some sort of auditing trigger, that captures who updated a row. You at the command line are a ‘who’ too.
Comment from OP:
Then either disable the trigger, or just delete the added history rows after. Even better, do your testing on a separate database, and just don’t worry about this at all.