sqoop导入命令,从关系型数据库到hive

参数说明,查看博文
https://blog.csdn.net/qq_41712271/article/details/101152891

首次导入,一般要加参数 --create-hive-table 自动创建表,或手工先在hive中创建好表(推荐)
再次导入,一般要加参数--delete-target-dir
注意:--hive-overwrite 参数有些诡异,最好不用

自动创建hive内部表,覆盖模式,先删除中间结果数据目录
sqoop import  \
--connect jdbc:mysql://127.0.0.1:3306/linshi_1   \
--username root  \
--password 123456   \
--table article  \
--fields-terminated-by "\t"  \
--lines-terminated-by "\n"  \
--m 1  \
--hive-import  \
--hive-overwrite  \
--create-hive-table  \
--delete-target-dir \
--hive-database  test01 \
--hive-table biao_2
 
 
用自定义的sql语句把MySQL数据导入到Hive中
sqoop import  \
--connect jdbc:mysql://127.0.0.1:3306/linshi_1   \
--username root  \
--password 123456   \
--fields-terminated-by "\t"  \
--lines-terminated-by "\n"  \
--m 1  \
--hive-import  \
--create-hive-table  \
--hive-database  test01 \
--hive-table biao_4 \
--query 'SELECT a.l_id,a.l_title,a.c_title FROM article AS a INNER JOIN e_left AS b  ON a.l_id=b.l_id WHERE $CONDITIONS and a.l_id=29' \
--target-dir /apps/hive/warehouse/test01.db/biao_4 
 

向hive的指定分区导入数据
sqoop import  \
--connect jdbc:mysql://127.0.0.1:3306/linshi_1   \
--username root  \
--password 123456  \
--table article  \
--where "l_id=57"  \
--columns "l_title,c_title"  \
--fields-terminated-by "\t"  \
--delete-target-dir   \
--hive-import  \
--m 1  \
--hive-partition-key l_id  \
--hive-partition-value '57'  \
--hive-database  test01  \
--hive-table biao_fq_2

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值