跟踪记录插入和删除 [英] Tracking record insertion and deletion

查看:71
本文介绍了跟踪记录插入和删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些软件,除其他外,需要跟踪数据库表的状态。这包括偶尔检查

表以查看记录或添加,修改或删除的记录。添加的

和修改过的部分并没有被证明太难实现,

但是有一种简单/优雅的方式来确定记录是什么

从mySQL表中删除了吗?


我非常喜欢mySQL,在阅读了关于日志的文档后,

唯一的东西我可以想出的是制作目标表的奴隶,

并以某种方式捕获删除语句,但在从奴隶删除它们之前先做一个选择




有没有人解决这个问题,可以提供一些建议或指示

来建议..

??


在此先感谢,

Dan

I am writing some software that, among other things, needs to track
the state of database tables. This includes occasionally checking the
table to see what records or added, modified, or deleted. The added
and modified parts of this have not proven too difficult to implement,
but is there an easy/elegant way to determine what records have been
deleted from a mySQL table ??

I''m very to mySQL, and after reading through the docs about logs, the
only thing I can come up with is to make a slave of the target table,
and somehow catch the delete statements, but do a select instead
before deleting them from the slave.

Has anyone tackled this problem and can offer some advice, or pointers
to advice..
??

Thanks in advance,
Dan

推荐答案

" Dan Greenblatt" <一个****** @ yahoo.com>在消息中写道
"Dan Greenblatt" <an******@yahoo.com> wrote in message
我正在编写一些软件,除其他外,需要跟踪数据库表的状态。这包括偶尔检查
表以查看记录或添加,修改或删除的记录。添加的
和修改后的部分并没有被证明太难实现,
但有一种简单/优雅的方法来确定从mySQL表中删除了哪些记录?

我非常喜欢mySQL,在阅读了关于日志的文档之后,我唯一能想到的就是制作目标表的奴隶,
和以某种方式捕获删除语句,但在从奴隶中删除它之前先做一个选择


有没有人解决这个问题,可以提供一些建议,或建议指点。 。
??
I am writing some software that, among other things, needs to track
the state of database tables. This includes occasionally checking the
table to see what records or added, modified, or deleted. The added
and modified parts of this have not proven too difficult to implement,
but is there an easy/elegant way to determine what records have been
deleted from a mySQL table ??

I''m very to mySQL, and after reading through the docs about logs, the
only thing I can come up with is to make a slave of the target table,
and somehow catch the delete statements, but do a select instead
before deleting them from the slave.

Has anyone tackled this problem and can offer some advice, or pointers
to advice..
??




也许最简单的建议是记录SQL语句。在

命令中心内,您可以说tee c:\ mylog \ state.txt。你也可以使用--tee选项启动mysql。


当然你必须解析tee文件。如果需要,你可以将这些语句存储到另一个MySql表中(但是不要使用tee,因为你需要记录这些插入语句。)b $ b想要记录这些插入语句。这一切都取决于你想要做什么

的信息。



Perhaps the simplest suggestion is to log the SQL statements. Within the
command center you can say "tee c:\mylog\statements.txt". You can also
start mysql with the --tee option.

Then of course you have to parse the tee file. If so desired you can store
the pieces of statements into another MySql table (but don''t use tee as you
want to log these insert statements). It all depends what you want to do
with the information.


如果它不会影响性能太多我会建议设置日志

表,并在此类更改之后(或之前)追加。我是开始用我的项目开始这么做的,这对跟踪

谁做了什么,以及确切改变了什么非常棒。非常适合

调试。一个日志文件可能会给你更多的信息 - 取决于

i猜测。

Dan Greenblatt写道:
if it won''t impact peformance too much i''d suggest setting up a log
table, and append to it straight after (or before) such changes. I''m
starting to do this with my projects and it''s been great for tracking
who did what when, plus exactly what has been changed. Great also for
debugging. A log file will probably give you more info though - depends
i guess.
Dan Greenblatt wrote:
我正在写一些软件,其中其他的东西,需要跟踪数据库表的状态。这包括偶尔检查
表以查看记录或添加,修改或删除的记录。添加的
和修改后的部分并没有被证明太难实现,
但有一种简单/优雅的方法来确定从mySQL表中删除了哪些记录?

我非常喜欢mySQL,在阅读了关于日志的文档之后,我唯一能想到的就是制作目标表的奴隶,
和以某种方式捕获删除语句,但在从奴隶中删除它之前先做一个选择


有没有人解决这个问题,可以提供一些建议,或建议指点。 。
??

提前致谢,
Dan
I am writing some software that, among other things, needs to track
the state of database tables. This includes occasionally checking the
table to see what records or added, modified, or deleted. The added
and modified parts of this have not proven too difficult to implement,
but is there an easy/elegant way to determine what records have been
deleted from a mySQL table ??

I''m very to mySQL, and after reading through the docs about logs, the
only thing I can come up with is to make a slave of the target table,
and somehow catch the delete statements, but do a select instead
before deleting them from the slave.

Has anyone tackled this problem and can offer some advice, or pointers
to advice..
??

Thanks in advance,
Dan





Dan Greenblatt <一个****** @ yahoo.com>在留言中写道

新闻:a2 ************************** @ posting.google.c om ...

"Dan Greenblatt" <an******@yahoo.com> wrote in message
news:a2**************************@posting.google.c om...
我正在编写一些软件,除其他外,需要跟踪数据库表的状态。这包括偶尔检查
表以查看记录或添加,修改或删除的记录。添加的
和修改后的部分并没有被证明太难实现,
但有一种简单/优雅的方法来确定从mySQL表中删除了哪些记录?

我非常喜欢mySQL,在阅读了关于日志的文档之后,我唯一能想到的就是制作目标表的奴隶,
和以某种方式捕获删除语句,但在从奴隶中删除它之前先做一个选择


有没有人解决这个问题,可以提供一些建议,或建议指点。 。
??
I am writing some software that, among other things, needs to track
the state of database tables. This includes occasionally checking the
table to see what records or added, modified, or deleted. The added
and modified parts of this have not proven too difficult to implement,
but is there an easy/elegant way to determine what records have been
deleted from a mySQL table ??

I''m very to mySQL, and after reading through the docs about logs, the
only thing I can come up with is to make a slave of the target table,
and somehow catch the delete statements, but do a select instead
before deleting them from the slave.

Has anyone tackled this problem and can offer some advice, or pointers
to advice..
??




希望这会有所帮助:


我认为日志文件会自动包含这些信息。


mysql>显示binlog事件;





mysql>在''< logfile>''中显示binlog事件;


将显示创建语句,更新和删除。


参考: (提示24:和提示2)
http ://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt


也可以写一个自动提取这个的C api

信息。对于示例程序,您可能需要下载

http://prdownloads.sourceforge.net/s...ar.gz?download


并查看selectbinlog .C" ;.或者,perl脚本可以写成

well ...(参见提示4 :)有关perl的基础知识和mysql。


这可以包含很多信息。您可能希望将其放入BerkeleyDB文件中,而不是将此信息

放入mysql表中。如果你是运行Linux或Unix的
,你可能已经安装了这个。 MySQL使用BerkeleyDB

。它不是真正的数据库,而是快速哈希或b树,取决于选择格式选项的
。有关如何编写BerkeleyDB api'

的示例,请参阅以下内容:
http://prdownloads.sourceforge.net/c...ar.gz?download


BerkeleyDB的最新版本允许加密,因此可以保护这些数据

。我使用BerkeleyDB进行这种类型的日志记录,因为我需要

来快速查找这些信息。


问候,


Mike Chirico



Hope this helps:

I think the log files automatically contain this information.

mysql> show binlog events;

or

mysql> show binlog events in ''<logfile>'';

will show the create statements, updates, and deletes.

Reference: ( TIP 24: and TIP 2) in
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

It''s also possible to write a C api that will automatically extract this
information. For an example program you may want to download

http://prdownloads.sourceforge.net/s...ar.gz?download

and take a look at "selectbinlog.c". Or, a perl script can be written as
well...(See TIP 4: ) for the basics on perl with mysql.

This can contain a lot of information. Instead of putting this information
into a mysql table, you may want to put it into a BerkeleyDB file. If you''re
running Linux or Unix you probably have this installed. BerkeleyDB is used
by MySQL. It''s not really a database but a fast hash or b-tree, depending
on format option selected. For an example of how to write BerkeleyDB api''s
see the following:
http://prdownloads.sourceforge.net/c...ar.gz?download

The latest version of BerkeleyDB allows for encryption, so that this data
can be protected. I use BerkeleyDB for this type of logging because I need
to do extremely quick lookups on this information.

Regards,

Mike Chirico


这篇关于跟踪记录插入和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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