Sqoop 的数据处理和开发--头歌
Posted Fdecad
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sqoop 的数据处理和开发--头歌相关的知识,希望对你有一定的参考价值。
第1关:Sqoop数据导入语法学习
start-all.sh
schematool -dbType mysql -initSchema
第2关:Mysql导入数据至HDFS上
mysql -uroot -p123123 -h127.0.0.1
create database hdfsdb;
use hdfsdb;
create table student(stu_no int primary key, stu_name varchar(20), stu_age int);
insert into student values(202001,"zhangsan",18);
insert into student values(202002,"lisi",19);
insert into student values(202003,"wangwu",20);
exit;
sqoop import --connect jdbc:mysql://127.0.0.1:3306/hdfsdb --username root --password 123123 --query 'select stu_name,stu_age from student where $CONDITIONS' --target-dir /user/root/hdfsdb3 --fields-terminated-by '-' -m 1
第3关:Mysql导入数据至Hive中
先在hive里面建表
hive
create table test2(stu_no int,stu_name string,stu_age int)
row format delimited
fields terminated by ",";
exit;
sqoop import --connect jdbc:mysql://127.0.0.1:3306/hdfsdb --username root --password 123123 --query 'select stu_no, stu_name,stu_age from student where stu_age>=20 and $CONDITIONS' --target-dir /user/root/hdfsdb6 --fields-terminated-by ',' -m 1
hive
load data inpath '/user/root/hdfsdb6/part-m-00000' into table test2;
注意!如果重置了代码仓库请用以下步骤:
start-all.sh
schematool -dbType mysql -initSchema
重置之后mysql数据库里数据没了,所以重新输入就行。
mysql -uroot -p123123 -h127.0.0.1
create database hdfsdb;
use hdfsdb;
create table student(stu_no int primary key, stu_name varchar(20), stu_age int);
insert into student values(202001,"zhangsan",18);
insert into student values(202002,"lisi",19);
insert into student values(202003,"wangwu",20);
exit;
hive
create table test2(stu_no int,stu_name string,stu_age int)
row format delimited
fields terminated by ",";
exit;
sqoop import --connect jdbc:mysql://127.0.0.1:3306/hdfsdb --username root --password 123123 --query 'select stu_no, stu_name,stu_age from student where stu_age>=20 and $CONDITIONS' --target-dir /user/root/hdfsdb6 --fields-terminated-by ',' -m 1
hive
load data inpath '/user/root/hdfsdb6/part-m-00000' into table test2;
这样就可以了。
有问题的话请提醒我。
以上是关于Sqoop 的数据处理和开发--头歌的主要内容,如果未能解决你的问题,请参考以下文章