sqoop基本操作

1.导出(mysql->hive)

sqoop export 
--connect "jdbc:mysql://ip:port/condata?useUnicode=true&characterEncoding=utf-8"  \
--username root \
--password Root@1234 \
--table mysql_table \
--export-dir "/user/hive/warehouse/app.db/hive_table" \
--input-fields-terminated-by "," \
-m 1

2.增量导出或更新(mysql->hive)

sqoop export 
--connect "jdbc:mysql://ip:port/condata?useUnicode=true&characterEncoding=utf-8" \ --username root \
--password Root@1234 \
--table mysql_table \
--export-dir "/user/hive/warehouse/app.db/hive_table/strpartitiondate=2018-04" \
--input-fields-terminated-by "," \
--update-key "monthkey,partner_id" \
--update-mode allowinsert

3.数据导入(hive->mysql)

sqoop import  
--connect jdbc:mysql://ip:port/easy_loan \
--table mysql_table \
--username slave_data \
--password ps \
--hive-import \
--hive-database dw \
--hive-table hive_table \
--fields-terminated-by "\t" \
--lines-terminated-by "\n" \
-m 1 \
--driver com.mysql.jdbc.Driver 

4.使用colums来指定导出到mysql的列

sqoop export 
--connect "jdbc:mysql://ip:port/xdata?useUnicode=true&characterEncoding=utf-8" \ 
--username "root" \
--password "Root@1234" \
--table "mysql_table" \
--export-dir "/data/user/hive/warehouse/app.db/hive_table/strpartitiondate=2018-06-11" \
--input-fields-terminated-by "\001" \
--update-key "datekey" \
--update-mode "allowinsert"  \
--columns="datekey,mall_out_amount,mall_in_amount,fenqi_out_amount,fenqi_in_amount,invest_out_amount,invest_in_amount" \
-m 1

5.导入

没有hive表可以create-hive-table
sqoop create-hive-table \
--driver com.mysql.jdbc.Driver \
--connect jdbc:mysql://10.16.3.13:3306/datacube_athena \
--table CF_MALL_ACTIVITY_THEME \
--username "prodmaster" \
--password "oa87(*FSD" \
--hive-database dw \
--hive-table cf_mall_activity_theme \
--fields-terminated-by "\t"
mysql存储为null,但是hive中存储null是\N,可以替换掉:
direct直连较快 overwrite直接覆盖hive表
sqoop import  \
--direct \
--hive-overwrite \
--driver com.mysql.jdbc.Driver \
--connect jdbc:mysql://192.168.254.220:3307/cs_business?zeroDateTimeBehavior=convertToNull  \
--table tboverduebill \
--username "slave_data" \
--password "ungsten@dafy098QWE123" \
--delete-target-dir \
--target-dir hdfs://bigdataservice/data/user/hive/warehouse/dw.db/dw_tboverduebill \
--hive-database dw \
--hive-table dw_tboverduebill \
--fields-terminated-by "\t" \
--null-string '\\N' \
--null-non-string '\\N' \
-m 1

转载于:https://my.oschina.net/lzhaoqiang/blog/3064526

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值