实验4 数据库安全性

ThisarticledelvesintousingSQLstatementsinMySQLfortaskssuchascreatingusers,alteringpasswords,andmanagingpermissions,withafocusongrantandrevokeoperations.
摘要由CSDN通过智能技术生成

一、实验项目:

数据库安全性。

实验目的

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;

  • 24
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值