Sqoop从mysql导数据到hdfs+从mysql导数据到hive

#mysql-hdfs
#where

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--driver com.mysql.jdbc.Driver \
	--table userinfos \
	--where 'userid<3' \
	--username root \
	--password root \
	--delete-target-dir \
	--target-dir /mytmp/datas \
	-m 1

#columns

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--driver com.mysql.jdbc.Driver \
	--table userinfos \
	--columns "userid" \
	--username root \
	--password root \
	--delete-target-dir \
	--target-dir /mytmp/datas02 \
	-m 1

#query

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--driver com.mysql.jdbc.Driver \
	--query "select a.*,u.username from(select max(case project when 'chinese' then score else 0 end) as chinese, max(case project when 'math' then score else 0 end) as math,userid from score group by userid)a inner join userinfos u on a.userid=u.userid where 1=1 and \$CONDITIONS" \
	--username root \
	--password root \
	--delete-target-dir \
	--target-dir /mytmp/datas03 \
	-m 1

#split-by

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--driver com.mysql.jdbc.Driver \
	--query "select a.*,u.username from(select max(case project when 'chinese' then score else 0 end) as chinese, max(case project when 'math' then score else 0 end) as math,userid from score group by userid)a inner join userinfos u on a.userid=u.userid where 1=1 and \$CONDITIONS" \
	--username root \
	--password root \
	--delete-target-dir \
	--split-by userid \
	--target-dir /mytmp/datas04 \
	-m 3

#append

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--driver com.mysql.jdbc.Driver \
	--table orders \
	--username root \
	--password root \
	--incremental append \
	--check-column orddate \
	--last-value '2020-11-09' \
	--target-dir /mytmp/orders

#mysql-hive

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--table userinfos \
	--username root \
	--password root \
	--hive-import \
	--hive-database mydemo \
	--hive-table users \
	-m 1

#往静态分区塞数据

create table orderinfos(
ordid string,
userid string
)
partitioned by (orddate string)

#–target-dir /mytmp/orderinfos 不指定回报错,指定后路径无效,会进入默认路径中

sqoop import \
	--connect jdbc:mysql://192.168.133.195:3306/mmm \
	--query "select ordid,userid from orders where orddate='2020-11-10' and \$CONDITIONS" \
	--username root \
	--password root \
	--target-dir /mytmp/orderinfos \
	--hive-import \
	--hive-database mydemo \
	--hive-table orderinfos \
	--hive-partition-key 'orddate' \
	--hive-partition-value '20201110' \
	-m 1
create table orderinfos(
ordid string,
userid string 
)
partitioned by (orddate string)
row format delimited fields terminated by ','
stored as parquetfile;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值