天天看點

資料庫記錄安全解決方案

中國廣東省深圳市龍華新區民治街道溪山美地

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的工具,可以逐行比較,通過色彩變化現實資料的不同。