- 在本地主机创建用户账号st_01,密码为123456。
CREATE USER st_01@localhost IDENTIFIED BY '123456';
- 查看MySQL下所有用户账号列表。
SELECT * FROM mysql.user;
- 修改用户账号st_01的密码为111111。
SET PASSWORD FOR st_01@localhost='111111';
- 使用studentsdb数据库中的student_info表。
(1)授予用户账号st_01查询表的权限。
(2)授予用户账号st_01更新家庭住址列的权限。
(3)授予用户账号st_01修改表结构的权限。 ```sql GRANT SELECT ON TABLE STUDENTDB.STUDENT_INFO TO st_01@localhost ;
GRANT UPDATE(家族住址) ON TABLE STUDENT.STUDENT_INFO TO st_01@localhost;
GRANT ALTER ON STUDENT.STUDENT_INFO TO st_01@localhost;
5. 使用studentsdb数据库中的student_info表。<br />(1)创建存储过程cn_proc,统计student_info表中的学生人数。<br />(2)授予用户账号st_01调用cn_proc存储过程的权限。<br />(3)以用户账号st_01连接MySQL服务器,调用cn_proc存储过程查看学生人数。
```sql
DELIMITER @@
CREATE PROCEDURE CN_PROC()
BEGIN
SELECT COUNT(*) FROM STUDENT_INFO;
END@@
DELIMITER;
GRANT EXECUTE ON PROCEDURE STUDENTDB.CN_PROC
TO st_01@localhost;
CALL CN_PROC();
- 使用studentsdb数据库。
(1)授予用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
(2)以用户账号st_01连接MySQL服务器,创建新表st_copy,与表student_info完全相同。
(3)以用户账号st_01连接MySQL服务器,删除表st_copy。 ```sql GRANT CREATE,DROP,SELECT,INSERT ON studentdb TO st_01@localhost;
DROP TABLE ST_COPY;
7. 撤消用户账号st_01在studentsdb数据库上创建表、删除表、查询数据、插入数据的权限。
```sql
REVOKE CREATE,DROP,SELECT,INSERT ON STUDENTDB.STUDENT_INFO
FROM st_01;
- 撤消用户账号st_01所有权限.
REVOKE ALL PRIVILEGES,GRANT OPTION
FROM st_01@localhost;
- 使用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。 ```sql use mysql; CREATE ROLE ‘student’@’localhost’;
grant select on studentdb.student_info to ‘student’@’localhost’;
create user st_02@localhost identied by ‘123’;
grant ‘student’@’localhost’ to st_02@localhost;
select * from studentdb.student_info;
revoke all privileges,grant option from ‘student’@’localhost’;
drop role ‘student’@’localhost’;
10.删除用户账号st_01、st_02。
```sql
drop user st_01@localhost,st_02@localhost;