在mysql中管理更改记录的审计跟踪的方法 [英] way to manage audit trail of changing record in mysql

查看:37
本文介绍了在mysql中管理更改记录的审计跟踪的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序.它基本上是一个电子商务订单履行应用程序.在这次审计试验中,即谁改变了什么以及改变了多少次,其他人是一个重要的方面.我应该如何在数据库/表级别维护它?假设一个记录被 3 个人更改,我将如何维护所有更改并跟踪谁更改了什么?

I am building a application. It is basically a E-commerce Order fulfillment application. IN this audit trials i.e. who changed what and how many times it was changed and others make a important aspect. How should i maintain this in database / table level ? Say if a record is altered by 3 people, how will i maintain all the changes and track of who changed what ?

推荐答案

首先,您需要为每个要跟踪的表创建如下结构:

First, you need create for every table which you want track with structure like this:

create table user_track_logs {

    id bigint(20) primary key auto_increment,
    key_id int (11),
    user_id (int),
    created timestamp default now(),
    field varchar(128)// set bigger if you have long named columns (like this_columns_is_very_important_for_me_and_my_employers...)
    field_value_was text null,
    field_value_new text null,    
}

其次你需要在 MySQL 的连接中的 var 中设置当前用户 ID,或者你可以使用 MySQL 的用户.您可以为每个用户创建单独的 MySQL 登录名.

Second you need set current user ID in var in MySQL's connection, or you can use MySQL's user. You can create for every user separate MySQL's login.

第三次创建触发插入/更新/删除,它们将存储在 user_track_logs 中.

Third create triggers insert/update/delete which will be store in user_track_logs.

或者你可以在 PHP 中模拟这个过程,但在 PHP 中会更困难.

Or you can emulate this process in PHP, but in PHP it will be more difficult.

这篇关于在mysql中管理更改记录的审计跟踪的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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