例程练习
- 4.11
代码:
CREATE ROLE role1 PASSWORD "role1@123"; 尝试登录role1,但是登录被拒绝,应该是没有登录权限; 创建新角色role2; CREATE ROLE role2 LOGIN PASSWORD 'role2@123'; 此时新角色可以登录,使用新角色在无权限的情况下对student表操作; 给角色2授权 GRANT SELECT,UPDATE,INSERT ON TABLE Student TO role2; 再次使用role2对student操作; select * from student; 将脚色role2授予仅有对sc表操作权限的user5; GRANT role2 TO user5; user5对表student操作;
运行结果
- 4.12
代码:
user5对表student操作; (插入测试数据)insert into student values('11111','test','test',999,'test'); 尝试删除测试数据; Delete from student where sno='11111'; 修改角色权限: GRANT DELETE ON TABLE student TO role2;
运行结果
- 4.13
代码:
收回角色的select权限; REVOKE SELECT ON TABLE student FROM role2; user5对表student操作测试; select * from student;
运行结果
- test
代码:
通过role2收回user5所有权限 REVOKE role2 from user5;
运行结果: