5

I'm creating a trigger in MySQL to let me know WHO (which mysql user) is doing an update on a specific table.

I know MySQL has a function CURRENT_USER(), but is that going to insert the username at the time the trigger is CREATED, or at the time the trigger is CALLED?

This is my trigger so far. I want to insert the username in the 'content' column.

delimiter |
CREATE TRIGGER update_product_procedure 
BEFORE UPDATE ON product_procedure 
FOR EACH ROW BEGIN 
INSERT INTO trigger_logs SET 
content = 'This is a test', postDate=NOW(); 
END;
|
1
  • 1
    Interesting question. My initial guess is that it will be the invoker, but I'll follow the question to see the real answer. Commented Nov 19, 2009 at 20:44

1 Answer 1

6

I would have put lots of money on it being the invoker, but from http://bugs.mysql.com/bug.php?id=5861:

SQL standard says that: "A triggered action is always executed under the authorization of the owner of the schema that includes the trigger." This means that in MySQL we should execute trigger body under authorization of user who created trigger and not the one who issued statement which invoked this trigger.

Apologies, I assumed it was an obvious question :-(

Regards

EDIT: user() gives the invoker

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. No worries. I picked USER(), which I didn't know existed.
Thanks for taking the time to research. I also didn't know about the USER(). Good to know :D
Probably obvious, but being able to get the user whose permissions apply to the trigger with CURRENT_USER() is also good to know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.