向 MySQL 单元添加时间维度
有没有办法保留 MySQL 表中每一行每一列的每次更改的时间戳记录? 这样我就永远不会丢失任何数据并保留转换的历史记录。 行删除可能只是将“已删除”列设置为 true,但可以恢复。
我正在研究 HyperTable,它是 Google BigTable,这个功能真是让我口水直流。 如果可以将其放在 MySQL 中那就太好了,因为我的应用程序无法处理证明部署 HyperTable 合理的大量数据。 有关其工作原理的更多详细信息,请参阅此处。
是否有任何配置、插件、fork 或任何可以向 MySQL 添加这一功能的东西?
Is there a way to keep a timestamped record of every change to every column of every row in a MySQL table? This way I would never lose any data and keep a history of the transitions. Row deletion could be just setting a "deleted" column to true, but would be recoverable.
I was looking at HyperTable, an open source implementation of Google's BigTable, and this feature really wet my mouth. It would be great if could have it in MySQL, because my apps don't handle the huge amount of data that would justify deploying HyperTable. More details about how this works can be seen here.
Is there any configuration, plugin, fork or whatever that would add just this one functionality to MySQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我过去在 php 模型中实现了这一点,类似于 Chaos 所描述的。
如果您使用的是 mysql 5,您还可以使用一个存储过程来完成此操作,该存储过程挂钩表的更新和删除事件。
http://dev.mysql.com/doc/refman/ 5.0/en/stored-routines.html
I've implemented this in the past in a php model similar to what chaos described.
If you're using mysql 5, you could also accomplish this with a stored procedure that hooks into the on update and on delete events of your table.
http://dev.mysql.com/doc/refman/5.0/en/stored-routines.html
我在自定义框架中执行此操作。 每个表定义还生成一个与主表多对一相关的日志表,并且当框架对主表中的行进行任何更新时,它将将该行的当前状态插入到日志表中。 所以我对表的状态有完整的审计跟踪。 (我有时间记录,因为我的所有表都有 LoggedAt 列。)
恐怕没有插件,更多的是一种需要融入整个数据库交互方法的方法。
I do this in a custom framework. Each table definition also generates a Log table related many-to-one with the main table, and when the framework does any update to a row in the main table, it inserts the current state of the row into the Log table. So I have a full audit trail on the state of the table. (I have time records because all my tables have LoggedAt columns.)
No plugin, I'm afraid, more a method of doing things that needs to be baked into your whole database interaction methodology.
创建一个存储以下信息的表...
现在创建一个执行此操作的存储过程...
一般来说,MyData 表只是一个键表。 然后将其指向数据表中最新的记录。 每当您需要更改数据时,您只需调用存储过程,它将新数据插入到数据表中,然后更新 MyData 以指向最新的记录。 如果系统中的其他表将自己与 MyData.ID 联系起来以用于外键目的,则一切都会发生。
这种安排避免了对第二个日志表的需要(并在架构更改时保持它们同步),但代价是在创建新记录时需要额外的联接和一些开销。
Create a table that stores the following info...
Now create a sproc that does this...
In general, the MyData table is just a key table. You then point it to the record in the Data table that is the most current. Whenever you need to change data, you simply call the sproc which Inserts the new data into the Data table, then updates the MyData to point to the most recent record. All if the other tables in the system would key themselves off of the MyData.ID for foreign key purposes.
This arrangement sidesteps the need for a second log table(and keeping them in sync when the schema changes), but at the cost of an extra join and some overhead when creating new records.
您是否需要它保持可查询性,或者这只是为了从错误的编辑中恢复? 如果是后者,您只需设置一个 cron 作业来备份 MySQL 存储数据的实际文件并将其发送到版本控制服务器。
Do you need it to remain queryable, or will this just be for recovering from bad edits? If the latter, you could just set up a cron job to back up the actual files where MySQL stores the data and send it to a version control server.