基于 MySQL 触发器的审计日志与比较 [英] MySQL Trigger based Audit logging with comparisons

查看:39
本文介绍了基于 MySQL 触发器的审计日志与比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看类似问题时:

获取触发器以插入更改的列值仅在审计表中

审计日志策略

我想更进一步,比较更新后的数据,看看它是否真的更新了...我不确定这是否理想(性能方面).

I would like to take this one step further and compare the updated data to see if it actually has been updated... I'm not sure if this is ideal (performance wise).

背景:

我们有一些用户会定期更新的数据.

We have some data that is periodically updated by the user.

当这些数据更新时,我想比较他们提交的内容与已经存在的内容以及他们提交的内容,以确保发生了变化.

When this data is updated, I would like to compare what they submitted with what is already there and what they submitted, to make sure there has been a change.

如果有变化,继续将审计条目写入中央审计​​历史记录表,概述更改的字段.

If there has been a change, proceed to write an audit entry to the central audit history table outlining the fields changed.

想法/想法?我尽了最大努力进行搜索,但运气不佳.如果它是重复的,我很乐意删除这个问题.

Thoughts/ideas? I did my best to search but didn't have a lot of luck. I'll be happy to delete this question if it's a duplicate.

谢谢!

推荐答案

您可以编写一个 BEFORE UPDATE 触发器,其中使用 OLDNEW 触发器中的别名,以将更新前记录中可用的值与您正在更新的值进行比较.根据比较结果,您可以将条目写入审计表.

You could write a BEFORE UPDATE trigger where you use the OLD and NEW aliases in your trigger to compare the values that were available in the record before the update with the values you are updating with. Depending on the result of the comparison you can write an entry to your audit table.

这篇关于基于 MySQL 触发器的审计日志与比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆