Use mysql user in trigger

mysql, triggers

Solution

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

Problem

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; | ```

Original source