Sqoop数据导入
input端 | output端 | 工具 | |
Sqoop import | mysql | hdfs hive | -m mr数量控制 增量添加时的配置 |
--connect --username --password
--table --columns --where
--query 'select * from tablename where 1 = 1 and $CONDITIONS'
| --target-dir # 中间文件路径 --delete-target-dir # 删除中间文件路径,不能与增量配置同时使用 --hive-import --hive-overwrite --hive-database xxx --hive-table xxx --hive-partition-key xxx --hive-partition-value xxx --create-hive-table | -m --split-by xxx
--fields-terminated-by 'xx' --lines-terminated-by 'xx'
--check-column xxx --incremental append/lastmodified --last-value 'xxxx'1 # 如果xxxx1 是日期 最 xxxx1 < date < 当前日期 的数据 |
把导入分为3个阶段
第一阶段:连接mysql 进行数据查询
--table xx
--columns xx
--where xx
--query 'select * from tablename where 1 = 1 and $CONDTIONS'
第二阶段:输出到hadoop hive hbase
--target-dir #定义中间文件目录
--hive-import
--hive-overwrite
--create-hive-table
--hive-database xxx
--hive-table xxx
--hive-partition-key xxx
--hive-partition-value xxx
--map-column-hive cost="DECIMAL",date="DATE" #指定字段类型映射
第三阶段:输出方式 mr数量 terminated分割 数据插入方式
#mr数量
-m num
--split-by id
#分割符定义
--fields-terminated-by 'xx'
--lines-terimnated-by 'xxx'
#空字符串处理
--input-null-non-string xxx
--input-null-string xxx
--null-non-string xxx
--null-string xxx