Sqoop的用法

hdfs 和 mysql 相互导入和导出

------------- hdfs---> mysql----------------
--建表
create table sqp_order(
creat_date date,
user_name varchar(20),
total_volume decimal(10,2)
)
---全都导
sqoop export \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--table sqp_order \
-m 1 \
--export-dir /kb12/sqp_order \
--fields-terminated-by '\t' 


------------ mysql -> hdfs ------------------
# 全导入
sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--table sqp_order \
-m 1 \
--delete-target-dir \
--target-dir /kb12/sqp_order2 \
--fields-terminated-by '\t' \
--lines-terminated-by '\n'
	

# 列裁剪
sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--table sqp_order \
--columns user_name \
-m 1 \
--delete-target-dir \
--target-dir /kb12/sqp_order3 \
--fields-terminated-by ',' \
--lines-terminated-by '\n'	

	
#行裁剪
sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--table sqp_order \
--columns user_name,total_volume \
--where "total_volume>=200" \
-m 2 \
--split-by user_name \
--delete-target-dir \
--target-dir /kb12/sqp_order4 \
--fields-terminated-by ',' \
--lines-terminated-by '\n' 
	
	
sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--query "select user_name,total_volume from sqp_order where total_volume>=300 and \$CONDITIONS" \
-m 2 \
--split-by user_name \
--delete-target-dir \
--target-dir /kb12/sqp_order5 \
--fields-terminated-by ',' \
--lines-terminated-by '\n' 


#增量导入 append|merge
sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--query "select * from studentinfo where \$CONDITIONS" \
-m 1 \
--target-dir /kb12/sqp_order6 \
--fields-terminated-by ',' \
--lines-terminated-by '\n' \
--check-column stuId \
--incremental append \
--last-value 0 

insert into studentinfo values
(50,'11',32,'男','14568758231',25201,6),
(51,'12',28,'男','15314381031',23489,7);


sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \
--query "select * from studentinfo where \$CONDITIONS" \
-m 1 \
--target-dir /kb12/sqp_order6 \
--fields-terminated-by ',' \
--lines-terminated-by '\n' \
--check-column stuId \
--incremental append \
--last-value 48 

#批量增加lastmodified(针对日期增加)
create table sqp_incr_time(
incrName varchar(20),
incrTime timestamp
);

insert into sqp_incr_time(incrName) values('m'),('h'),('c'),('zhangsan');
insert into sqp_incr_time() values 


sqoop import \
--connect jdbc:mysql://mch:3306/test \
--username root \
--password 12345678 \ 
--query "select * from sqp_incr_time where \$CONDITIONS" \
-m 1 \
--target-dir /kb12/sqp_order7 \
--fields-terminated-by ',' \
--lines-terminated-by '\n' \
--check-column incrTime \
--incremental lastmodified \
--last-value '0000-00-00 00:00:00'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值