一、实验项目:
数据库安全性。
二、实验目的
1、会使用SQL语句创建和删除用户。
2、会使用SQL语句授予和回收用户权限。
3、会使用SQL语句进行角色的相关操作。
三、实验内容
使用SQL语句完成下列题目:
1、创建agristore数据库管理用户a0001、店员用户s0001和顾客用户u0001,主机地址为localhost,密码均为123456。
2、将用户a0001的密码改为admin123。
3、授予用户u0001对agristore库中product表的select操作权限。
4、授予用户u0001对agristore库中account表的姓名列和地址列的UPDATE权限。
5、授予用户a0001对所有库的所有操作权限。
6、授予用户s0001对agristore库中所有表的select操作权限,并允许其将该权限授予其他用户。
7、收回用户u0001对agristore库中account表上的UPDATE操作权限。
8、创建可在任意主机上使用的顾客角色customer。
四、实验参考代码及执行结果截图
1、create user
a0001@localhost identified by '123456',
s0001@localhost identified by '123456',
u0001@localhost identified by '123456';
创建用户后:select user from mysql.user;
2、update mysql.user set password=PASSWORD('admin123') where user='a0001' and host='localhost';
或者
update mysql.user set authentication_string=md5('admin123') where user='a0001' and host='localhost';
修改密码前:
MySQL5:Select user, password from mysql.user where user='a0001';
MySQL8:Select user, authentication_string from mysql.user where user='a0001';
修改密码后:
3、grant select on product to u0001@localhost;
Show grants for u0001@localhost;
4、grant update(fullname,address)on account to u0001@localhost;
Show grants for u0001@localhost;
5、grant all on *.* to a0001@localhost;
Show grants for a0001@localhost;
MySQL5得出的截图:
MySQL8得出的截图:
6、grant select on agristore.* to s0001@localhost with grant option;
Show grants for s0001@localhost;
7、revoke update on agristore.account from u0001@localhost;
Show grants for u0001@localhost;
8、CREATE ROLE 'customer';
select user from mysql.user;