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