简体   繁体   English

MySQL限制插入/更新/删除要从触发器调用(不是从应用程序代码)

[英]Mysql limit insert/update/delete to being called from trigger (Not from application code)

My use case is that I have a MYSQL table which has a change tracking table behind it. 我的用例是我有一个MYSQL表,后面有一个更改跟踪表。 Both tables are InnoDB. 这两个表都是InnoDB。
I'd like to use triggers to enforce two things. 我想使用触发器来强制执行两件事。

One : forcing a copy to be made of previous state on every update (update trigger performs insert select query) This is non-trivial and I have already done it. 一个 :强制在每次更新时复制以前的状态(更新触发器执行插入选择查询)这很简单,我已经做过了。

Two : limit access to the second table to read only for users, while triggers can still insert/update/delete as necessary :将对第二张表的访问限制为仅对用户只读,而触发器仍可以根据需要插入/更新/删除

Further research on user access and triggers has dug up this: 对用户访问和触发器的进一步研究已经挖掘出了这一点:

Mysql 5.5 reference manual: 19.6 Access Control for Stored Programs and Views Mysql 5.5参考手册:19.6存储程序和视图的访问控制

Turns out that stored programs can be assigned a user to run as. 事实证明,可以为存储的程序分配一个用户以其身份运行。 Triggers are stored programs. 触发器是存储的程序。 By restricting Insert, Update, and Delete to a special user which only will be used by a trigger and using the DEFINER attribute of the trigger (or any stored program) I can make the trigger which I want to have access run under that user. 通过将“插入,更新和删除”限制为仅由触发器使用的特殊用户,并使用触发器(或任何存储的程序)的DEFINER属性,可以使要访问的触发器在该用户下运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM