将每次更新、删除、插入查询添加到 MySQL 中的新记录 [英] Add every update, delete, insert query to a new record in MySQL

查看:37
本文介绍了将每次更新、删除、插入查询添加到 MySQL 中的新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在记录发生更改时,将更改数据(更新、删除、插入)的查询透明地添加到历史"表中?

Is there a way that if there's a change in records, that a query that changed the data (update, delete, insert) can be added to a "history" table transparently?

例如,如果 mySQL 检测到一条或一组记录中的更改,mySQL 是否可以将该查询语句添加到单独的表中,以便我们可以跟踪更改?这将使回滚"成为可能,因为每个查询(SELECT 除外)都能够从其第一行重建数据库.正确的?

For example, if mySQL detects a change in a record or set of records, is there a way for mySQL to add that query statement into a separate table so that way, we can track the changes? That would make "rollback" possible since every query (other than SELECT) would be able to reconstruct database from its first row. Right?

我使用 PHP 与 mySQL 交互.

I use PHP to interact with mySQL.

推荐答案

您需要启用 MySQL BinLog.这会自动将所有更改语句记录到二进制日志中,可以根据需要进行回复.

You need to enable the MySQL BinLog. This automatically logs all the alteration statements to a binary log which can be replied as needed.

另一种方法是通过触发器使用审计功能

这篇关于将每次更新、删除、插入查询添加到 MySQL 中的新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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