一、实验目的:
1. 了解用户与权限的作用;
2. 掌握Create User创建用户;
3. 掌握Alter User设置密码;
4. 掌握GRANT授予用户权限;
5. 熟练掌握视图的创建和视图数据的操作。
二、实验内容:
1.完成教材P196动手实践:用户与权限练习。
2、完成教材P199实训题第1题。
3、完成教材第8章的动手实践。
三、实验结果的截图
题目一:
1.
CREATE USER if not EXISTS 'shop'@'127.0.0.%'
IDENTIFIED by '123456'
2.将密码设置为过期
ALTER USER 'shop'@'127.0.0.%' PASSWORD EXPIRE;
3.修改用户密码
show databases
Alter User 'shop'@'127.0.0.%' Identified By '2c5-98h';
4.为用户设置权限
Grant Select On shop.sh_goods
To 'shop'@'127.0.0.%';
Drop Table shop.sh_goods;
5.回收用户权限
Revoke Select On shop.sh_goods
From 'shop'@'127.0.0.%';
Drop User If Exists 'shop'@'localhost';
教材P199实训题第1题。
1.
CREATE USER if not EXISTS 'xiaoming'@'localhost'
IDENTIFIED by '123abc'
2.
Grant Select On shop.*
To 'xiaoming'@'localhost';
第8章的动手实践。
1. 创建sh_view_attr 视图
Create View sh_view_attr As Select a.sort sort1,a.name attr1,b.sort sort2,b.name attr2,
b.category_id From sh_goods_attr a Join sh_goods_attr b On a.id=b.parent_id
Where b.parent_id!=0 Order By a.sort ASC,b.sort ASC;
2.查询sh_view_attr 视图
SELECT * FROM sh_view_attr WHERE category_id=6
3.sh_view_goods_attr 视图
Create View sh_view_goods_attr AS Select b.name attr1,a.name attr2,c.attr_value,c.goods_id
From sh_goods_attr a Join sh_goods_attr b On a.parent_id=b.id Join sh_goods_attr_value c
On a.id=c.attr_id Where a.parent_id !=0 Order By b.sort ASC, a.sort ASC;
4.查询sh_view_goods_attr 视图
Select * From sh_view_goods_attr Where goods_id=5;