简单使用Sqoop的命令

一、import命令

1.将mysql表test中的数据导入hive的hivetest表,hive的hivetest表不存在
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive 
--password hive --table test --hive-table hivetest --hive-import -m 1

2.在1的基础上,分别进行overwrite导入和into(直接加入)导入
into:命令同1
overwrite:
	sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive 
	--password hive --table test --hive-table hivetest --hive-import -m 1 --hive-overwrite
	
3.在2的基础上,通过增加mysql的test表数据,增量导入到hive表中
	sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive 
	--password hive --table test --where "id>3" --hive-table hivetest --hive-import -m 1
	或者
	sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive 
	--password hive --table test --query "select id,name from test where id>3" --hive-table hivetest --hive-import -m 1

4.将test表中数据导出到使用','分割字段的hive表中(hivetest2)中
	创建表:create table hivetest2(id int,name string) row format delimited fields terminated by ',';
	sqoop:
		sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive --table test 
		--hive-table hivetest2 --hive-import -m 1 --fields-terminated-by ","

5.将test表中数据导入到hdfs中。
	sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive --table test 
	--target-dir /test -m 1
	
6.在5的基础上,增量导出数据到hdfs中
	sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive 
	--table test --target-dir /test -m 1 --check-column id --incremental append --last-value 11

二、export命令

1.将hdfs上的文件导出到关系型数据库test2表中
	sqoop export --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive 
	--table test2 --export-dir /test		
	
2.将hive表(hivetest)数据导出到关系型数据库test2表中(使用insertOrUpdate方法导入)
	hivetest表分割方式是'\u0001',但是export命令默认使用','分割数据
	sqoop export --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive 
	--table test2 --export-dir /hive/hivetest --input-fields-terminated-by "\\01" --update-mode 
	allowinsert --update-key id
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值