irpas技术客

Sqoop 的数据处理和开发--头歌_Fdecad_sqoop开发

网络 2491

第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;

这样就可以了。

有问题的话请提醒我。


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #sqoop开发 #schematool #dbType #MySQL #initschema #uroot