开发者

Use mysql user in trigger

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜