sqoop导入数据命令实现

SQOOP是用于对数据进行导入导出的。
    (1)把MySQL、Oracle等数据库中的数据导入到HDFS、Hive、HBase中

    (2)把HDFS、Hive、HBase中的数据导出到MySQL、Oracle等数据库中

1.把数据从mysql导入到hdfs(默认是/user/<username>)中,使用sqoop import命令

sqoop import --connect jdbc:mysql://192.168.80.100:3306/hive  --username root --password admin --table TBLS --fields-terminated-by '\t'

2.把数据从mysql导入到hdfs中,处理掉null的字段,把null字段使用**来代替,注意不能使用--来代替null

sqoop import --connect jdbc:mysql://192.168.80.100:3306/hive  --username root --password admin --table TBLS --fields-terminated-by '\t' --null-string '**'

3.按照1和2放的方式进行数据导入,hadoop会默认分配多个map来执行,最终数据导入到多个目录下,可以设置使用一个map来导入数据,讲数据导入到hdfs中同一目录下

sqoop import --connect jdbc:mysql://192.168.80.100:3306/hive  --username root --password admin --table TBLS --fields-terminated-by '\t' --null-string '**' -m 1

4.按照1,2,3的方式进行数据导入,不是追加数据的方式,如果原来已经在hdfs上存在了目录,则需要删除原目录,再导入,使用append命令可以实现追加

sqoop import --connect jdbc:mysql://192.168.80.100:3306/hive  --username root --password admin --table TBLS --fields-terminated-by '\t' --null-string '**' -m 1 --append

5.将数据导入到hive中

sqoop import --connect jdbc:mysql://192.168.80.100:3306/hive  --username root --password admin --table TBLS --fields-terminated-by '\t' --null-string '**' -m 1 --append --hive-import


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值