要求:
一、在数据库中创建一个表student,用于存储学生信息
CREATE TABLE student(
id INT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
grade FLOAT
);
1、向student表中添加一条新记录
记录中id字段的值为1,name字段的值为"monkey",grade字段的值为98.5
2、向student表中添加多条新记录
2,"bob",95.5
3,"john",90.0
4,"smith",88.5
3、向student表中添加一条新记录,部分数据插入
5,"jone"
4、更新表,grade 大于90的加0.5
5、删除成绩为空的记录
二、用户权限部分
1、创建一个用户test1使他只能本地登录拥有查询student表的权限。
2、查询用户test1的权限。
3、删除用户test1.
内容:
一、在数据库中创建一个表student,用于存储学生信息
首先创建一个数据库用于该次存储(也可以使用以前建好的数据库),并将要求填入
create database if not exists student_information; //创建叫student_information的数据库
use student_information; //使用该数据库(也可直接跳过创建,直接使用以前创建好的数据库)
1、向student表中添加一条新记录
记录中id字段的值为1,name字段的值为"monkey",grade字段的值为98.5
即数据插入:
mysql> insert into student(id,name,grade)values(1,"monkey",98.5);
3、向student表中添加一条新记录,部分数据插入
5,"jone"
insert into student(id,name)values(5,"jone");
使用select * from student查询数据,可以看到现在的表:
4、更新表,grade 大于90的加0.5
即数据修改:
update student set grade=grade+0.5 where grade>90; //where后加条件
此时再用select * from student查询数据,可以看到修改后的表:
5、删除成绩为空的记录:
即删除数据:
delete from student where grade is null; //where后面加条件
此时再用select * from student查询数据,可以看到修改后的表:
二、用户权限部分
1、创建一个用户test1使他只能本地登录拥有查询student表的权限
创建用户test1:
create user 'test1'@'localhost' identified by '123456';
授予其本地登录查询student表的权利:
grant select ON student_information.student TO'test1'@'localhost'; //GRANT 权限… ON 数据库名称.表名称 TO 用户名@用户地址
2、查询用户test1的权限
show grants for 'test1'@'localhost';
3、删除用户test1
在此之前,可以先使用revoke select ON student_information.student FROM 'test1'@'localhost'; 撤销权限(但也可以直接删除用户test1)
drop user 'test1'@'localhost'; //删除用户
最后使用use mysql + select * from user可以查看发现该用户已经被删除