题目数据
drop database if exists StudentManage;
create database StudentManage;
use StudentManage;
create table Student
(Sno int primary key,
Sname nchar(10) ,
Ssex nchar(2),
Sage int,
Sdept nvarchar(30));
create table Course
(Cno int primary key,
Cname nvarchar(30),
Cpno int,
Ccredit int);
create table SC
(Sno int,
Cno int,
Grade int,
primary key(Sno,Cno));
insert into Student
values(201215121,'Li Yong','Male',20,'CS'),
(201215122,'Liu Chen','Female',19,'CS'),
(201215123,'王敏', 'Female',18,'MA'),
(201215124,'Zhang Li','Male',19,'IS');
insert into Course
values(1,'database',5,4),(2,'mathematics',NULL,2),
(3,'information system',1,4),(4,'operating system',6 ,3),
(5,'Data Structure',7,4),(6,'Data Processing',NULL,2),
(7,'PASCAL',6,4);
insert into SC
values(201215121,1,92),(201215121,2,85),
(201215121,3,88),(201215122,2,90),(201215122,3,80);
1. View the user name and host information of all users.
select user,host from mysql.user;
2. Create a simple user user1.
create user ‘user1’;
3. View the permissions currently owned by user1.
show grants for ‘user1’;
4. Create user user2 with a password of 123456, and create user user3 with a password of 123456.
create user
‘user2’@’%’ identified by ‘123456’,
‘user3’@’%’ identified by ‘123456’;
5. Modify user user1 with a password of 123456, and limit the maximum number of users that can connect to the server at the same time to 3.
alter user user1 identified by ‘123456’
with max_user_connection 3;
6. Modify user user1, the password is 888888, the password never expires, the account is locked.
alter user user1 identified by ‘888888’
password expire never account lock;
7. Rename the user user1 to first.
rename user user1 to first;
8. Delete user first.
drop user first;
9. Grant all administrative rights to the administrator user2 and allow him to grant these rights to others.
grant all privileges on * . *
to ‘user2’ with grant option;
10. Grant user3 the query permissions on the student table in the StudentManage database.
grant select on Studentmanage.student to user3;
11. Grant user3 the table update permission in the StudentManage database.
grant update on studentmanage.* to use r3;
12. Reclaim user3's query and update permissions on the Student table, and refresh the permissions. ①Recover permissions; ②Refresh permissions.
第一空:
revoke select,update on studentmanage.student from user3;
The second empty:
flush privileges;
13. (Switch user2 account login) Create user user4 with a password of 123456, grant all permissions of the sc table in the database to user4, and allow user4 to grant these permissions to other users. ①Create user user4; ②Authorize user4.
第一空:
create user ‘user4’@’%’ identified by ‘123456’;
The second empty:
grant all privileges on Studentmanage.sc to user4
with grant option;
14. Create user user5, the password is 123456. (Switch user4 account login) Give user5 the query authority of the sc table in the database. ①Create user user5; ②Authorize user5.
The first empty:
create user'user5'@'%' identified by '123456';
Second empty:
grant select on Studentmanage.sc to user5;
15. (Switch back to root login) Reclaim all permissions of user2 and refresh permissions.
First empty:
revoke all privileges, grant option from user2;
The second empty:
flush privileges;