数据库系统(三)——数据库安全性控制
一、實驗目的:
理解自主存取控制和視圖機制在數據庫安全性中的應用;
熟練掌握用戶管理、授予權限、收回權限的SQL語句,并驗證其有效性;
理解角色的作用,能夠區分角色和用戶。
二、實驗內容:
針對不同用戶對學生選課數據庫的不同權限要求,完成以下實驗內容。
創建用戶。掌握創建用戶的語法結構,根據題目要求運用相關SQL語句創建必要的用戶。
創建視圖。根據題目要求,創建針對特定數據的視圖。
權限授予和收回。理解和掌握GRANT和REVOKE語法結構的各個組成成分,結合用戶和角色管理,分別設計不同的存取權限語句,并調試成功。
結合應用需求,理解角色的作用和角色管理的相關操作。
三、實驗過程:
1、題目要求:
1.數據庫:學生選課數據庫
2.數據表:學生表 student、課程表 course、選課表 SC
3.用戶:admin、stu、teacher、
4.權限要求:
說明:
(1)admin 用戶擁有對數據庫的所有操作權限,且能夠為其他用戶授予權限。
(2)teacher 用戶在 student 表上只能查看 Sno、Sname、Ssex 和 Sdept 字段。
(2)學生不能更新 Sno 和院系字段。
(3)teacher 在 SC 表上只能更新 grade 字段。
2、在學生選課數據庫的基礎上,按以下要求完成權限設置。
1、使用 root 賬號登錄,創建用戶 stu、teacher 和 amdin,密碼為123:
create user 'stu'@'localhost' identified by '123';create user 'teacher'@'localhost' identified by '123';create user 'admin'@'localhost' identified by '123' with grant option;新創建的用戶可登錄mysql,但無權限查看stu_course數據庫。
2、根據表格要求及說明為用戶設置相應的權限,并在設置完成后,測試設置的有效性。
①設置 admin 的權限:
grant all privileges on student,course,SC to 'u1'@'localhost' with grant option②設置 stu 的權限:
grant select on student,course,SC to'stu'@'localhost';grant update on student to'stu'@'localhost';grant insert on SC to'stu'@'localhost';③設置 teacher 的權限:
grant select on student,course,SC to 'teacher'@'localhost';grant update on SC(grade) to 'teacher'@'localhost';3、創建用戶 u1 和 u2,通過 admin 用戶為 u1 授予 student 表上的 insert 權限,并允許 u1為其他用戶授予該權限。
create user 'u1'@'localhost' identified by '123';create user 'u2'@'localhost' identified by '123'; grant insert on student to 'u1'@'localhost'; with grant option4、通過 u1 用戶為 u2 用戶授予 student 表上的 insert 權限。
grant insert on student to 'u2'@'localhost';5、收回 u1 在 student 表上的 insert 權限,驗證 u1 和 u2 的權限變化。
revoke insert on student to 'u1'@'localhost';默認會級聯收回權限。
總結
以上是生活随笔為你收集整理的数据库系统(三)——数据库安全性控制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库系统(二)——数据更新和视图
- 下一篇: 数据库系统(四)——触发器