管理员准备在MySQL数据库中创建课程管理网站需要的数据库(couman)和相关表。数据表包括学生信息表(student)、课程描述表(course)、学生选课表(stucou),各个表的结构如下:
学生信息表(student)字段:学号(sno)、姓名:(sname)、性别(sex)、班级(class),其中序号(sid)字段为主键;
学生信息表(course)字段:学号(cno)、姓名:(cname),其中序号(cid)字段为主键;
学生信息表(stucou)字段:学号(sno)、姓名:(cno)、成绩(score),其中序号(scid)字段为主键,学号(sno)和课程号(cno)为外键;
数据表创建成功后,向每个表中至少插入三条合法记录;
赋予guestuser1用户对数据库的远程登录、数据查询(select)权限;
赋予guestuser2用户对数据库的远程登录、数据库(couman)权限;
赋予guestuser3用户对数据库的远程登录、数据的增、删、改、查(insert,delete,update,select)权限;
赋予guestuser4用户对数据库的所有权限;
同时管理员对couman数据库进行备份。
yum -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum repolist enable|grep "mysql"
yum -y remove mariadb-libs
yum install mysql-community-server
systemctl start mysqld
cat /var/log/mysqld.log | grep password
Mysql -u root -p
输入默认密码
修改root登录MySQL服务器的密码
alter user 'root'@'localhost' identified with mysql_native_password by "Mysql123!";
create database couman;
show database;
use couman;
create table student (
sno varchar(10) not null,
sname varchar(50) not null,
sex int(10) not null,
class varchar(20) not null,
primary key(sno)
);
describe student;
create table course(
cno varchar(10) not null,
cname varchar(50) not null,
primary key(cno)
);
describe course;
create table stucou(
scid int(10) not null auto_increment,
sno varchar(10) not null,
cno varchar(10) not null,
score int(5),
primary key(scid),
constraint foreign key(sno) references student(sno),
constraint foreign key(cno) references course(cno)
);
describe stucou;
insert into student(sno,sname,sex,class) values('1001','zhangsan',1,'a1');
insert into student(sno,sname,sex,class) values('1002','zhangsi',2,'a1');
insert into student(sno,sname,sex,class) values('1003','zhangwu',1,'a1');
insert into course(cno,cname) values('4','lisan');
insert into course(cno,cname) values('5','lisi');
insert into course(cno,cname) values('6','liwu');
insert into stucou(1,'1001','4',7);
insert into stucou(2,'1002','5',8);
insert into stucou(3,'1003','6',9);
exit;
create user 'guestuser1'@'localhost' identified by 'Mysql123!';
create user 'guestuser2'@'localhost' identified by 'Mysql123!';
create user 'guestuser3'@'localhost' identified by 'Mysql123!';
create user 'guestuser4'@'localhost' identified by 'Mysql123!';
grant select on *.* to 'guestuser1'@'%' identified by 'Mysql123!' with grant option;
grant all privileges on couman.* to 'guestuser2'@'%’ identified by 'Mysql123!' with grant option;
grant insert,delete,update,select on *.* to 'guestuser3'@'%' identified by 'Mysql123!' with grant option;
grant all privileges on *.* to 'guestuser4'@'%' identified by 'Mysql123!' with grant option;
cd /user/bin
mysqldump -u root -p couman>couman.sql
Mysql123!
cd /user/bin
ls