hive 建库建表插入数据

hive 建库建表插入数据

先上传文件

sftp> put /Users/chenxin/Downloads/HQL50/HQL50/score.txt /root/data/hql50

sftp> put /Users/chenxin/Downloads/HQL50/HQL50/teacher.txt /root/data/hql50 

sftp> put /Users/chenxin/Downloads/HQL50/HQL50/course.txt /root/data/hql50

sftp> put /Users/chenxin/Downloads/HQL50/HQL50/student.txt /root/data/hql50

在hdfs 建文件夹 将传上去的文件存到hdfs中

hdfs dfs -mkdir /homework
hdfs dfs -put course.txt /homework
hdfs dfs -put score.txt /homework
hdfs dfs -put student.txt /homework
hdfs dfs -put teacher.txt /homework

去50070端口查看是否传上去了

hive 建库用库

create database homework;
use homewrok;

建表

create table if not exists course(
course_id int,course_name string,teacher_id int
) COMMENT 'course table' 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\n' 
STORED AS TEXTFILE;
create table if not exists score(
student_id int,course_id int,score int
) COMMENT 'score table' 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\n' 
STORED AS TEXTFILE;
create table if not exists student(
student_id int,student_name string,
student_birth string,student_sex string
) COMMENT 'student table' 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\n' 
STORED AS TEXTFILE;
create table if not exists teacher(
teacher_id int,
Display all 478 possibilities? (y or n)
ame string
) COMMENT 'teacher table' 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\n' 
STORED AS TEXTFILE;

查看表是否建完成

show tables;

将hdfs文件中数据插入表中

load data inpath'/homework/course.txt' into table course;
load data inpath'/homework/score.txt' into table score;
load data inpath'/homework/student.txt' into table student;
load data inpath'/homework/teacher.txt' into table teacher;

查看表中是否有数据

select * from teacher;

你可能感兴趣的:(hive)