天天看点

数据库记录安全解决方案

中国广东省深圳市龙华新区民治街道溪山美地

518131

+86 13113668890

+86 755 29812080

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

数据库记录安全解决方案

文档出处:

<a href="http://netkiller.github.io/" target="_top">http://netkiller.github.io</a>

<a href="http://netkiller.sourceforge.net/" target="_top">http://netkiller.sourceforge.net</a>

2014-08-19

摘要

防删除,放撰改,灵活性解决方案

我的系列文档

<a href="http://netkiller.github.io/architect/index.html" target="_top">netkiller architect 手札</a>

<a href="http://netkiller.github.io/developer/index.html" target="_top">netkiller developer 手札</a>

<a href="http://netkiller.github.io/php/index.html" target="_top">netkiller php 手札</a>

<a href="http://netkiller.github.io/python/index.html" target="_top">netkiller python 手札</a>

<a href="http://netkiller.github.io/testing/index.html" target="_top">netkiller testing 手札</a>

<a href="http://netkiller.github.io/cryptography/index.html" target="_top">netkiller cryptography 手札</a>

<a href="http://netkiller.github.io/linux/index.html" target="_top">netkiller linux 手札</a>

<a href="http://netkiller.github.io/debian/index.html" target="_top">netkiller debian 手札</a>

<a href="http://netkiller.github.io/centos/index.html" target="_top">netkiller centos 手札</a>

<a href="http://netkiller.github.io/freebsd/index.html" target="_top">netkiller freebsd 手札</a>

<a href="http://netkiller.github.io/shell/index.html" target="_top">netkiller shell 手札</a>

<a href="http://netkiller.github.io/security/index.html" target="_top">netkiller security 手札</a>

<a href="http://netkiller.github.io/www/index.html" target="_top">netkiller web 手札</a>

<a href="http://netkiller.github.io/monitoring/index.html" target="_top">netkiller monitoring 手札</a>

<a href="http://netkiller.github.io/storage/index.html" target="_top">netkiller storage 手札</a>

<a href="http://netkiller.github.io/mail/index.html" target="_top">netkiller mail 手札</a>

<a href="http://netkiller.github.io/docbook/index.html" target="_top">netkiller docbook 手札</a>

<a href="http://netkiller.github.io/version/index.html" target="_top">netkiller version 手札</a>

<a href="http://netkiller.github.io/database/index.html" target="_top">netkiller database 手札</a>

<a href="http://netkiller.github.io/postgresql/index.html" target="_top">netkiller postgresql 手札</a>

<a href="http://netkiller.github.io/mysql/index.html" target="_top">netkiller mysql 手札</a>

<a href="http://netkiller.github.io/nosql/index.html" target="_top">netkiller nosql 手札</a>

<a href="http://netkiller.github.io/ldap/index.html" target="_top">netkiller ldap 手札</a>

<a href="http://netkiller.github.io/network/index.html" target="_top">netkiller network 手札</a>

<a href="http://netkiller.github.io/cisco/index.html" target="_top">netkiller cisco ios 手札</a>

<a href="http://netkiller.github.io/h3c/index.html" target="_top">netkiller h3c 手札</a>

<a href="http://netkiller.github.io/multimedia/index.html" target="_top">netkiller multimedia 手札</a>

<a href="http://netkiller.github.io/perl/index.html" target="_top">netkiller perl 手札</a>

<a href="http://netkiller.github.io/radio/index.html" target="_top">netkiller amateur radio 手札</a>

<a href="http://netkiller.github.io/devops/index.html" target="_top">netkiller devops 手札</a>

目录

<a href="http://netkiller.github.io/journal/mysql.security.html#what">1. 什么是防删除,防撰改</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#why">2. 为什么要做防删除,防撰改限制</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#when">3. 何时做防删除,防撰改限制</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#where">4. 在哪里做防删除,防撰改限制</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#who">5. 谁去做防删除,防撰改限制</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#how">6. 怎么做防删除,防撰改限制</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#idp57201872">6.1. 限制删除</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#idp57204320">6.2. 限制修改</a>

<a href="http://netkiller.github.io/journal/mysql.security.html#idp57207040">6.3. 版本控制</a>

禁止数据删除,数据一旦增加不允许数据被任何人删除

禁止数据修改,数据一旦建立不允许对数据做修改操作

很多时候我们的数据是只增加,不会删除数据。有些敏感子段一旦数据家里是不允许再修改的,例如银行账户表中的资金子段。

另一个原因是我们防止误操作

你可以取消用户的 delete 权限,使之只能做查询操作,但修改(update)呢?你就无能为力!如果取消update程序将不能正常运行。

程序设计之初你就应该想到这些问题,如果没有考虑倒,你只能修改现有逻辑。通常的做法是所有表增加一个删除状态子段,删除操作即是更新状态。这种方式也有弊端就是垃圾数据会不停地膨胀。

我认为可以分为两种人,一种是dba,一种是开发者。这里主要将数据库部分。

对account表中的记录做删除操作,数据库抛出异常 permission denied

在数据库修改前我们覆盖掉修改的数据,使之更新后数据保持不变。

主表

本版控制表,用于记录每次变动

任何数据的变化都会复制一份到历史表,我们可以随时比较两个版本数据的变化,我还为此开发了一个类似diff的工具,可以逐行比较,通过色彩变化现实数据的不同。