sqoop导入/导出

导入到HDFS

全部导入

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'

查询导入

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--target-dir /user/test1 \
--delete-target-dir \
--m 1 \
--fields-terminated-by '\t' \
--query 'select * from students where $CONDITIONS'

注意:sql语句末尾必须加上$CONDITIONS
 

导入指定列

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t' \
--columns id,sex 

提示:columns中如果涉及到多列,用逗号分隔,分隔时不要添加空格

关键字筛选查询导入数据

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t' \
--where "id=2"

导入到Hive

1. 直接导入到hive

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--m 1 \
--hive-import \
--fields-terminated-by "\t" \
--hive-overwrite \
--hive-table students

提示:Hive中的表要存在,不存在不会自动创建

2. 导入到HDFS然后load到Hive

     1.导入到HDFS

sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'

     2.load 到Hive

load  data  inpath '/user/test1'  into  table  hive表名字 

导出到MySQL

sqoop export \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--export-dir /user/test1 \
--table students \
--input-fields-terminated-by '\t'
--m 1

提示:导出数据时MySQL表必须存在

猜你喜欢

转载自blog.csdn.net/drl_blogs/article/details/90930836