资讯详情

实验二 数据库安全性技术

1、理解安全性的概念。

了解用户的相关概念。

3、掌握MySQL安全技术、系统权限和对象权限的授予和回收方法。

综合性实验

2H

现在有两种关系模式:

部门(部门号、名称、经理名称、地址、电话号码)

职工(职工号、姓名、年龄、职务、工资、部门号)

1.创建数据库demo,并根据上述关系模式创建部门和员工表,每个表插入两个测试数据。

创建部门表

create table dept(  dno char(4),  dname varchar(20),  dmanager varchar(8),  address varchar(50),  phone varchar(20)  );

创建职工表

create table emp(  eno char(4),  ename varchar(8) not null,  age int,  djob varchar(10),  salary DECIMAL(9,2),  dno char(4));

向部门表添加数据

insert into dept values人事部,王明,湖北汽车工业学院,823877  insert into dept values1002,销售部,李勇,湖北汽车工业学院,823878

将数据添加到员工表中

 insert into emp values人事处长,5000,1001,  insert into emp values(0002,李四,30,销售经理,3000,1002);

定义用户,使用SQL的GRANT和REVOKE完成以下授权定义或访问控制功能。

⑴ 创建数据库本地用户test,密码为1234。test有两个表SELECT权力。(15分)

create user 'testss'@'localhost' identified by '1234';

授予语句

 grant select on demo.dept to 'testss'@'localhost';   grant select on demo.emp to 'testss'@'localhost';

收回语句

 revoke select on demo.dept from 'testss'@'localhost';   revoke select on demo.emp from 'testss'@'localhost';

⑵ 用户王明有员工和部门表INSERT和DELETE权力。(15分)

create user '王明'@'localhost' identified by '11111111';  grant insert,delete,select on demo.dept to '王明'@'localhost';  grant insert,delete,select on demo.emp to '王明'@'localhost';

⑶ 用户李勇有员工表SELECT有权更新工资字段。(15分)

create user '李勇'@'localhost' identified by '1234';  grant select,update(salary) on demo.emp to '李勇'@'localhost';

⑷ 用户周平有权向其他用户授权两张表的所有权(读、插、改、删数据)。

提示:所有权为ALL PRIVILEGES,在GRANT语句中使用WITH GRANT OPTION被授权的用户有能力再次将对象权限授予其他用户。(15分)

reate user '周平'@'localhost' identified by '1234';  grant all privileges on demo.dept to '周平'@'localhost' with grant option; grant all privileges on demo.emp to '周平'@'localhost' with grant option;  revoke all privileges on demo.dept to '周平'@'localhost'; revoke all privileges on demo.emp to '周平'@'localhost';

3.用户杨兰有来自各部门的员工SELECT他无法检查每个人的最高工资、最低工资和平均工资。提示:首先创建视图查询各部门员工的最高工资、最低工资和平均工资,然后授予用户查询视图的权限。(20分)

create user '杨兰'@'localhost' identified by '1234';  create view v_sal as select dept.dname,max(salary),min(salary),avg(salary) from emp,dept  where dept.dno=emp.dno group by emp.dno;  grant select on demo.v_sal to '杨兰'@'localhost';

标签: le36sn08dno传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台