sqoop常用命令

使用


1 mysql导入数据到HDFS   
1.1  ./sqoop import --connect jdbc:mysql://192.168.116.132:3306/sqoop --username root --password 123456 --table test_user --target-dir /sqoop/test_user -m 2 --fields-terminated-by "\t" --columns "id,name"  --where 'id>2 and id<=6'

--connect 连接数据库
--username 用户
--password 密码
--table 表名
--target-dir 目标目录/sqoop/test_user
-m 2个mapreduce执行
--fields-terminated-by 用“\t”分隔 不用逗号默认是逗号.
--columns 只导入 id和name两个字段
--where  添加条件筛选 语句要用引号抱起来



1.2  ./sqoop import --connect jdbc:mysql://192.168.116.132:3306/sqoop --username root --password 123456 --query 'select * from test_user where id < 9 and id > 1 and $CONDITIONS'  --target-dir /sqoop/test_user4 -m 2 --split-by test_user.id

--query 直接用查询语句 这样就可以join 查询多表
-m 1 的时候可以执行 大于1就不行 如果要多个map要设置每个map读多少数据用--split-by分隔
--split-by test_user.id


2.hdfs数据导出到mysql
 
2.1 ./sqoop export --connect jdbc:mysql://192.168.116.132:3306/sqoop --username root --password 123456 --export-dir '/sqoop/test_user5' --table test_user -m 2

--export-dir 需要导出的目录/sqoop/test_user5


3.mysql导入到hive中
./sqoop import --hive-import --connect jdbc:mysql://192.168.116.132:3306/sqoop --username root --password 123456 --table test_user -m 2 --hive-table hive_user

--hive-import 指定导入到hive中
--hive-table 导入到hive中的表hive_user 如果没有表会自动创建
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

white......

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值