hive实验 1.创建数据库,数据库名: db_experiment2.切换到创建好的数据库 db_experiment3.创建表:学生表(student)、课程表(course)、教师表(teac

所有操作基于xshell和DG

首先应该保证hive与DG连接是成功的,不然无法继续进行后续操作

实验内容

1.创建数据库,数据库名: db_experiment

2.切换到创建好的数据库: db_experiment

3.创建表:学生表(student)、课程表(course)、教师表(teacher)、分数表(score

字段要求:

①学生表:学生id(stu_id)、学生姓名(stu_name)、出生日期(birthday)、性别(sex)

②课程表:课程id(course_id)、课程名(course_name)、教师id(tea_id)

③教师表:教师id(tea_id)、教师姓名(tea_name)

④分数表:学生id(stu_id)、课程id(course_id)、分数(score)

其他要求:

①每一张表字段分隔符设置为’,’(英文逗号)

②存储文件类型指定为 textfile

4.数据准备

创建文件:student.txt、course.txt、teacher.txt、score.txt

数据如下:

①student.txt

001,王德发,1995-05-16,男

002,胡先林,1994-03-20,男

003,周大福,1995-04-30,男

004,刘德明,1998-08-28,男

005,唐明里,1993-09-10,男

006,陈显坤,1992-11-12,男

007,陈钟宇,1999-04-09,男

008,吴后贤,1994-02-06,男

009,郭先宇,1992-12-05,男

010,于智,1998-08-23,男

011,潘世明,1995-05-27,男

012,杨丽丽,1996-12-21,女

013,蒋心雨,1997-11-08,女

014,赵小芬,1990-01-09,女

015,刘菲菲,1993-01-14,女

016,周雨,1990-06-18,女

017,范贤斌,1992-07-04,女

018,李丽,1993-09-24,女

019,邓紫嫣,1994-08-31,女

020,宋小菲,1991-03-01,女

②course.txt

01,语文,1003

02,数学,1001

03,英语,1004

04,体育,1002

05,音乐,1002

③teacher.txt

1001,张高数

1002,李体音

1003,王子文

1004,刘丽英

④score.txt

001,01,94

002,01,74

004,01,85

005,01,64

006,01,71

007,01,48

008,01,56

009,01,75

010,01,84

011,01,61

012,01,44

013,01,47

014,01,81

015,01,90

016,01,71

017,01,58

018,01,38

019,01,46

020,01,89

001,02,63

002,02,84

004,02,93

005,02,44

006,02,90

007,02,55

008,02,34

009,02,78

010,02,68

011,02,49

012,02,74

013,02,35

014,02,39

015,02,48

016,02,89

017,02,34

018,02,58

019,02,39

020,02,59

001,03,79

002,03,87

004,03,89

005,03,99

006,03,59

007,03,70

008,03,39

009,03,60

010,03,47

011,03,70

012,03,62

013,03,93

014,03,32

015,03,84

016,03,71

017,03,55

018,03,49

019,03,93

020,03,81

001,04,54

002,04,100

004,04,59

005,04,85

007,04,63

009,04,79

010,04,34

013,04,69

014,04,40

016,04,94

017,04,34

020,04,50

005,05,85

007,05,63

009,05,79

015,05,59

018,05,87

5.插入数据(将数据文件中的数据加载到创建的表中)

6.验证数据(查询结果)

第一步

创建并使用数据库

create database db_experiment;
Use db_experiment;

第二步

创建所需要的表

create table student(
    stu_id  int,
    stu_name  string,
    birthday  string,
    sex string
)
row format delimited fields terminated by ',' stored as textfile;

create table course(
    course_id  int,
    course_name  string,
    tea_id  int
)
row format delimited fields terminated by ',' stored as textfile;

create table teacher(
    tea_id  int,
    tea_name string
)
row format delimited fields terminated by ',' stored as textfile;

create table score(
    stu_id  int,
    course_id  int,
    score int
)
row format delimited fields terminated by ',' stored as textfile;

第三步

在桌面创建所对应的文本文档,讲数据储存到txt文件中

执行语句将数据写入表中

load data local inpath '/opt/module/hive/datas/student.txt' into table student;
load data local inpath '/opt/module/hive/datas/course.txt' into table course;
load data local inpath '/opt/module/hive/datas/teacher.txt' into table teacher;
load data local inpath '/opt/module/hive/datas/score.txt' into table score;

成功后应该显示

第四步

查看数据是否插入成功?

SELECT * FROM student;
SELECT * FROM course;
SELECT * FROM teacher;
SELECT * FROM score;

结束实验

  • 35
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值