实验内容

  1. 在本地主机创建用户账号st_01,密码为123456。
  2. 查看MySQL下所有用户账号列表。
  3. 修改用户账号st_01的密码为111111。
  4. 使用studentsdb数据库中的student_info表。
    (1)授予用户账号st_01查询表的权限。
    (2)授予用户账号st_01更新家庭住址列的权限。
    (3)授予用户账号st_01修改表结构的权限。
  5. 使用studentsdb数据库中的student_info表。
    (1)创建存储过程cn_proc,统计student_info表中的学生人数。
    (2)授予用户账号st_01调用cn_proc存储过程的权限。
    (3)以用户账号st_01连接MySQL服务器,调用cn_proc存储过程查看学生人数。
  6. 使用studentsdb数据库。
    (1)授予用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
    (2)以用户账号st_01连接MySQL服务器,创建新表st_copy,与表student_info完全相同。
    (3)以用户账号st_01连接MySQL服务器,删除表st_copy。
  7. 撤消用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
  8. 撤消用户账号st_01所有权限.
  9. 使用studentsdb数据库中的student_info表。
    (1)创建本地机角色student。
    (2)授予角色student查询student_info表的权限。
    (3)创建本地机用户账号st_02,密码为123。
    (4)授予用户账号st_02角色student的权限。
    (5)以用户账号st_02连接MySQL服务器,查看student_info表信息。
    (6)撤消用户账号st_02角色student的权限。
    (7)删除角色student。
    10.删除用户账号st_01、st_02。

实验步骤及处理结果

粘贴SQL代码(小四号,宋体)及运行结果图

思考体会

参考资料


# 附 代码
#删除角色student。
#drop role 'student'@'localhost'
#删除用户账号st_01、st_02。
#drop USER st_01@localhost,st_02@localhost;
#角色和账户不同哦

#1. 在本地主机创建用户账号st_01,密码为123456。
CREATE USER st_01@localhost IDENTIFIED BY'123456';

#2. 查看MySQL下所有用户账号列表。
USE mysql;
SELECT * FROM USER;

#3. 修改用户账号st_01的密码为111111。
SET PASSWORD FOR st_01@localhost ='111111';

#4. 使用studentsdb数据库中的student_info表。

#(1)授予用户账号st_01查询表的权限。
GRANT SELECT ON TABLE studentsdb.student_info TO st_01@localhost;

#(2)授予用户账号st_01更新家庭住址列的权限。
GRANT UPDATE(家庭住址) ON TABLE studentsdb.student_info TO st_01@localhost;

#(3)授予用户账号st_01修改表结构的权限。
GRANT ALTER ON TABLE studentsdb.student_info TO st_01@localhost;

#5. 使用studentsdb数据库中的student_info表。
#(1)创建存储过程cn_proc,统计student_info表中的学生人数。
DELIMITER@@
CREATE PROCEDURE studentsdb.cn_proc()
BEGIN
DECLARE n INT;
SELECT COUNT(*) INTO n FROM studentsdb.student_info;
SELECT n;
END@@

#(2)授予用户账号st_01调用cn_proc存储过程的权限。
DELIMITER
GRANT EXECUTE on PROCEDURE studentsdb.cn_proc TO st_01@localhost;

#(3)以用户账号st_01连接MySQL服务器,调用cn_proc存储过程查看学生人数。
CALL studentsdb.cn_proc();



#6. 使用studentsdb数据库。
#(1)授予用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
GRANT CREATE,SELECT,INSERT,DROP ON studentsdb.* TO st_01@localhost;

#(2)以用户账号st_01连接MySQL服务器,创建新表st_copy,与表student_info完全相同。
CREATE TABLE studentsdb.st_copy SELECT * FROM studentsdb.student_info;

#(3)以用户账号st_01连接MySQL服务器,删除表st_copy。
DROP TABLE studentsdb.st_copy;


#7. 撤消用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
revoke CREATE,SELECT,INSERT,drop on studentsdb.* FROM st_01@localhost;

#8. 撤消用户账号st_01所有权限.
REVOKE ALL PRIVILEGES,GRANT OPTION FROM st_01@localhost;


#9. 使用studentsdb数据库中的student_info表。
#(1)创建本地机角色student。
CREATE role 'student'@'localhost';

#(2)授予角色student查询student_info表的权限。
GRANT SELECT ON TABLE studentsdb.student_info TO 'student'@'localhost';

#(3)创建本地机用户账号st_02,密码为123。
CREATE USER st_02@localhost IDENTIFIED by '123';

#(4)授予用户账号st_02角色student的权限。
GRANT 'student'@'localhost' TO st_02@localhost;
SET GLOBAL activate_all_roles_on_login = ON;

#(5)以用户账号st_02连接MySQL服务器,查看student_info表信息。
SELECT * FROM studentsdb.student_info;

#(6)撤消用户账号st_02角色student的权限。
revoke ALL PRIVILEGES ,GRANT OPTION FROM 'student'@'localhost';

#(7)删除角色student。
drop role 'student'@'localhost';

#10.删除用户账号st_01、st_02。
drop USER st_01@localhost,st_02@localhost;

Logo

本社区面向用户介绍CSDN开发云部门内部产品使用和产品迭代功能,产品功能迭代和产品建议更透明和便捷

更多推荐