第 4 章 数据库安全性控制
1. 授权与收回
// 把查询 Student 表的权限授予用户 U1
grant select on table Studnet to U1;
// 把对 Student 和 SC 的全部权限授予用户 U1 和 U3
grant all privileges on table Student, SC to U1, U3;
// 把对表 SC 的查询权限授予所有用户
create select on table SC to public;
// 把对表 SC 的 insert 权限授予用户 U5 ,并允许此权限再授予其他人
grant insert on table SC to U5 with grant option;
// 把用户 U4 修改学生学号的权限收回
revoke update(Sno) on table Student from U4;
// 收回所有用户对表 SC 的查询权限
revoke select on table from public;
// 把用户 U5 对 SC 表的 insert 权限收回
revoke insert on table SC from U5 cascade;
2. 数据库角色
// 创建角色 R1
create role R1;
// 使角色 R1 拥有 Student 表的 select、insert、update 权限
grant select, insert, update on table Student to R1;
// 将这个角色授予王平、张明、赵玲
grant R1 to 王平、张明、赵玲;
// 收回王平的角色
revoke R1 from 王平;
// 角色权限的修改,使角色在原来基础上拥有 delete 权限
grant delete on table Student to R1;
// 使 R1 减少 select 角色
revoke select on table from R1;
3. 审计
数据库安全审计系统是一个事后检查的安全机制,将特定用户或特定对象的操作记录到系统的审计日志中。
// 对修改 SC 表结构或数据的操作进行审计
audit alter,update on SC;
// 取消对 SC 表的一切审计
noaudit alter,update on SC;