底层
常用参数
sqoop 导入常用参数:
bin/sqoop import
------------------------------公有参数-----------------------------------
--connect 指定mysql url连接
--username 指定mysql账号
--password 指定mysql的密码
-------------------------------导入HDFS的时候使用---------------------------
--append 追加数据到HDFS
--as-textfile 将数据以文本格式保存在HDFS
--as-parquetfile 将数据以parquet文件格式保存在HDFS--columns 指定从mysql导出哪些列的数据到HDFS
--delete-target-dir 指定导入数据之前先删除目标路径
--num-mappers[-m] 指定maptask的个数,这多maptask并行从mysql导数据
--split-by 指定数据切分的依据字段
--query[-e] 通过sql语句指定从mysql导哪些数据 [select 字段,... from 表名 where ...and \$CONDITIONS\ (加了Conditions后面的多个map才能平均切分)]
--where 指定导入mysql指定条件的数据
--table 指定导mysql哪个表的数据
--columns 指定从mysql导出哪些列的数据到HDFS
--target-dir 指定数据存储在HDFS的路径
--compress[-z] 指定数据导入HDFS的时候是否压缩
--compression-codec 指定数据保存在HDFS的时候压缩格式
--null-string 指定mysql字符串列值如果为null的时候导入HDFS以哪种格式保存
--null-non-string 指定mysql非字符串列值如果为null的时候导入HDFS以哪种格式保存
--fields-terminated-by 指定数据保存在HDFS的时候列之间的分隔符
--lines-terminated-by 指定数据保存在HDFS的时候行之间的分隔符
-------------------------------------增量导入------------------------------
--check-column 指定通过哪个字段判断数据为新增/修改数据
--incremental append[只导mysql每天新增的数据]/lastmodified[导入新增和修改的数据]
--last-value 指定通过哪个值判断数据为新增/修改的数据
------------------------------------数据导入HIVE--------------------------
--hive-import 指定数据导入HIVE中
--hive-table 指定数据导入hive哪个表
--create-hive-table 如果hive表不存在可以自动创建
--hive-overwrite 指定数据导入hive的时候直接覆盖hive数据
--hive-partition-key 指定数据导入hive分区表的时候分区字段名是什么
--hive-partition-value 指定数据导入hive分区表的时候分区字段的值是什么
示例
bin/sqoop import --connect jdbc:mysql://hadoop102:3306/gmall \
--username root \
--password root123 \
--as-textfile \
--delete-target-dir \
--num-mappers 4 \
--split-by id \
--query "select * from user_info where id<=100 and \$CONDITIONS" \
--target-dir hdfs://hadoop102:8020/user_info \
--null-string '\\N' \
--null-non-string '\\N' \
--fields-terminated-by ,
sqoop 导出常用参数:
bin/sqoop export
------------------------------公有参数-----------------------------------
--connect 指定mysql url连接
--username 指定mysql账号
--password 指定mysql的密码
--columns 指定数据导入到mysql哪些列中
--export-dir 指定HDFS数据路径
--num-mappers[-m] 指定maptask个数
--table 指定数据导入到mysql哪个表
--update-key 指定HDFS导入数据到mysql的时候,通过哪个字段判断HDFS与mysql的数据是同一条数
--update-mode updateonly[如果update-key的数据在mysql中已经存在则更新,不存在则忽略]/allowinsert[如果update-key的数据在mysql中已经存在则更新,不存在则插入]
--input-null-string 指定HDFS字符串数据如果为null,保存在mysql的时候以哪种形式保存
--input-null-non-string 指定HDFS非字符串数据如果为null,保存在mysql的时候以哪种形式保存
--input-fields-terminated-by 指定HDFS中数据字段之间的分隔符
--input-lines-terminated-by 指定HDFS中数据行之间的分隔符
示例
bin/sqoop export \
--connect jdbc:mysql://hadoop102:3306/test \
--username root \
--password root123 \
--columns id,name,age \
--export-dir hdfs://hadoop102:8020/input \
--num-mappers 1 \
--table user_info \
--update-key id \
--update-mode allowinsert \
--input-null-string "null" \
--input-null-non-string "null" \
--input-fields-terminated-by ,