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;

这样就可以了。

有问题的话请提醒我。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Akihiris

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值