简体   繁体   English

MySQL:是否在更新/删除时从硬盘安全删除了列数据?

[英]MySQL: is column data safely deleted from hard drive on update/delete?

Suppose I have one table called 'privacy': 假设我有一张称为“隐私”的表:

privacy (id INT PRIMARY KEY, data BINARY(512))

Suppose I insert one row in such table: 假设我在这样的表中插入一行:

INSERT INTO privacy(1, 'CIPHERTEXT')

with CIPHERTEXT the pseudo random bytes result of an AES encryption of certain plaintext. 使用CIPHERTEXT时,伪随机字节是某些明文的AES加密的结果。

My concern comes when UPDATING the data column or DELETING such row: Indeed, for privacy reasons, I don't want that someone who access my server retreive erased data values. 更新data列或删除这样的行时,我会担心:确实,出于隐私原因,我不希望访问我的服务器的人检索删除的data值。

Does MySQL really delete the previous data from the hard drive when UPDATE/DELETE commands are sent ? 发送UPDATE / DELETE命令时,MySQL是否真的从硬盘中删除了先前的数据? Must we UPDATE the row with random data before DELETE command execution ? 在执行DELETE命令之前,是否必须使用随机数据更新该行?

Note: my server use an SSD hard drive with TRIM enabled and tables engines are InnoDB. 注意:我的服务器使用启用了TRIM的SSD硬盘驱动器,并且表引擎为InnoDB。

Thanks. 谢谢。

When InnoDB updates a record there are two paths possible: InnoDB更新记录时,有两种可能的路径:

  1. if new record size is the same (which the case for your table btw) then the new record is written at the same position as the old one. 如果新记录的大小是相同的(表的情况就是这样),那么新记录将被写入与旧记录相同的位置。 Ie the new record overwrites the old one. 也就是说,新记录将覆盖旧记录。
  2. If record size is different then the new record is added to the end of used data and the old record is marked as deleted. 如果记录大小不同,则将新记录添加到已用数据的末尾,并将旧记录标记为已删除。 Take into account the old record in both cases is copied to rollback segment. 考虑到两种情况下的旧记录都将复制到回滚段。 See however Marc B's comment - there is no guarantee the new record is written at the same physical position on disk. 请参阅Marc B的评论-无法保证新记录将写入磁盘上的相同物理位置。

When InnoDB deletes a record, it's not deleted actually - the record is marked as free. InnoDB删除记录时,实际上并没有删除它-该记录被标记为空闲。 The deleted record may stay in a page for a while until B+ tree is rebalanced (read - a lot of records are inserted or deleted). 删除的记录可能会在页面中停留一段时间,直到重新平衡B +树(已读取-插入或删除了大量记录)为止。

Having said that your old record is recoverable with high chance of success no matter what you do. 话虽如此,无论您做什么,您的旧记录都是很容易获得成功的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM