蓝桥云MySQL基础-挑战二
1 minute read
由同学SQl整理
蓝桥云MySQL基础实验-挑战二
下载csv数据并解压
wget http://labfile.oss.aliyuncs.com/contestlou2/loudatabase.zip
unzip loudatabase.zip;
启动MySQL并进入
sudo service mysql start;
mysql -uroot;
创建数据库并使用
create database shiyanlou;
use shiyanlou;
创建用户并赋权
create user 'shiyanlou' @ 'localhost' identified by 'shiyanlou';
grant all privileges on shiyanlou.* to 'shiyanlou'@'localhost';
创建用户表并导入数据
create table user(
id int NOT NULL,
name varchar(10) NOT NULL,
PRIMARY KEY(id)
);
load data infile '/home/shiyanlou/loudatabase/shiyanlou_user.csv' into table user fields terminated by',';
创建课程表并导入数据
create table course(
id int NOT NULL,
name varchar(30) NOT NULL,
PRIMARY KEY(id)
);
load data infile '/home/shiyanlou/loudatabase/shiyanlou_course.csv' into table course fields terminated by',';
创建选课表并导入数据
create table usercourse(
id int NOT NULL AUTO_INCREMENT,
user_id int NOT NULL,
course_id int NOT NULL,
study_time int NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(user_id) REFERENCES user(id),
FOREIGN KEY(course_id) REFERENCES course(id)
);
load data infile '/home/shiyanlou/loudatabase/shiyanlou_usercourse.csv' into table usercourse fields terminated by','(user_id,course_id,study_time);
I feedback.
Let me know what you think of this article in the comment section below!
Let me know what you think of this article in the comment section below!