资源描述:
《实验五mysql权限与安全》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验五 MYSQL权限与安全实验平台:安装MYSQL数据库的PC实验目的:1.理解MYSQL权限管理的工作原理。2.掌握MYSQL中账号管理。实验具体要求(在导入的教学管理STM数据库中完成):1、用户的创建①利用CREATEUSER语句创建用户user1、user2、user3,密码均为’123456’。mysql>createuser'user1'@'localhost'identifiedby'123456','user2'@'localhost'identifiedby'123456','use
2、r3'@'localhost'identifiedby'123456';QueryOK,0rowsaffected(0.00sec)②利用INSERTINTO语句向USER表创建用户user4,密码均为’123456’。mysql>insertintomysql.user(host,user,password,ssl_cipher,x509_issuer,x509_subject)values('localhost','user5',password('123456'),'','','');QueryO
3、K,1rowaffected(0.00sec)③利用GRANT语句创建用户user5,密码均为’123456’,且为全局级用户。mysql>grantselect,insert,updateon*.*to'user5'@'localhost'identifiedby'123456';QueryOK,0rowsaffected(0.00sec)2、用户授权(利用GRANT语句)①授予user1用户为数据库级用户,对STM拥有所有权。mysql>grantallon*.*to'user1'@'localho
4、st'identifiedby'123456';QueryOK,0rowsaffected(0.01sec)②授予user2用户为表级用户,对STM中的student表select,create,drop权限。mysql>grantselect,create,droponstm.学生to'user2'@'localhost'identifiedby'123456';QueryOK,0rowsaffected(0.00sec)③授予user3用户为列级用户,对STM中的student表的sname列用户s
5、elect和update权限。mysql>grantselect,update(姓名)onstm.学生to'user2'@'localhost'identifiedby'123456';QueryOK,0rowsaffected(0.02sec)④授予user4用户为过程级用户,对STM中的get_student_by_sno存储过程拥有EXECUTE执行的权限。mysql>grantexecuteonprocedureget_student_by_snoto'user4'@'localhost'ide
6、ntifiedby'123456';QueryOK,0rowsaffected(0.00sec)利用上述建立的用户连接并登陆MYSQL数据库,对相关权限进行验证。查看权限mysql>select*frommysql.userwhereuser='test1';Emptyset(0.00sec)mysql>showgrantsfor'root'@'localhost';select*frommysql.userwhereuser='root';mysql>deletefrommysql.userwhere
7、user="root"andhost="localhost";QueryOK,1rowaffected(0.00sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)删除权限mysql>dropuser'user4'@'localhost';QueryOK,0rowsaffected(0.00sec)3、权限回收①收回user3用户对STM中的student表的sname列的update权限。mysql>revokeupdateon*.*from
8、'user2'@'localhost';QueryOK,0rowsaffected(0.00sec)②收回user4用户对STM中的get_student_by_sno存储过程拥有EXECUTE执行的权限。mysql>revokeexecuteonprocedureget_student_by_snofrom'user4'@'localhost';QueryOK,0rowsaffected(0.00sec)利用上述建立的用户连接并登陆MYS