Sqoop—使用指南

1.sqoop命令入门

  • sqoop hele: 查看所有帮助命令
  • sqoop help command: 查看某个命令的使用
  • 命令分解
--connect                指定关系型数据库的连接url  mysql:jdbc:mysql://主机:3306
--username               指定mysql的用户名
--password               指定mysql的密码
--table                  指定mysql中需要的表名
-m                       指定maptask的个数
--target-dir             指定导入的hdfs的目标路径
--fields-terminated-by   指定列之间的分隔符
--columns                指定需要导入的列名
--where                  指定过滤条件
--query                  指定查询语句
--split-by               指定多个maptask切分依
--lines-terminated-by    指定数据的行的分隔符 默认 \n
--hive-overwrite         覆盖导入
--create-hive-table      在hive中创建表
--hive-database          指定hive的数据库
--hive-table             指定hive中的表名

2.MySQL导入HDFS

#普通导入
sqoop import \
--connect jdbs:mysql://hdp01:3306/bd1810 \
--username root \
--password root \
--table stu_test \
--targt-dir /user/BigTree/stu_test        指定HDFS中的目标路径,若不指定默认user/${username}/tableName
--fields-terminated-by '\t'               指定导出数据列间的分隔符
-m 1

#过滤导入
sqoop import \
--connect jdbc:mysql://hdp01:3306/mysql \
--username root \
--password root \
--columns "name" \  
--where "help_keyword_id>400" \           指定过滤条件
--table help_keyword \
--target-dir /user/data01/mydata/res_where \
-m 1

#sql语句导入
sqoop import \
--connect jdbc:mysql://hdp01:3306/ \
--username root \
--password root \
--target-dir /user/data01/mydata/res_sql \
--query 'select * from mysql.help_keyword where help_keyword_id > 200 and $CONDITIONS' \       指定查询语句
--split-by help_keyword_id \            指定mapTask切分依据
--fields-terminated-by '\t' \
-m 2

3.MySQL导入到hive

#全量导入
sqoop import \
--connect jdbc:mysql://hdp01:3306/mysql \
--username root \
--password root \
--table help_keyword \
--fields-terminated-by "\t" \
--hive-import \
--hive-overwrite \                覆盖导入
--create-hive-table \
--delete-target-dir \             删除临时文件
--direct \      使用MySQL自带的导出功能更快
--hive-database student \         指定导入hive的数据库(必须存在)
--hive-table new_help_keyword     指定表(不能存在,自动创建)

#增量导入
sqoop import \
--connect jdbc:mysql://hdp01:3306/mysql \
--username root \
--password root \
--table help_keyword \
--target-dir /user/data01/mydata/res_add \   
--incremental append \     指定增量导入类型:append/lastmodified
--check-column help_keyword_id \     指定检验列  
--last-value 200 \     
-m 1

4.从MySQL导入到HBase

sqoop import \ 
--connect jdbc:mysql://hadoop02/bigdata \      连接到MySQL
--username root \
--password root \
--table student \
--hbase-table studenttest \ 
--column-family info \ 
--hbase-row-key id

5.从hive导出到MySQL

sqoop export \
--connect jdbc:mysql://hdp02:3306/sqoopdb \      
--username root \
--password root \
--table uv_info \                           指定导出到MySQL的表(必须存在,先创建)
--export-dir /user/hadoop/warehouse/help_keyword \      指定hive数据源在HDFS的路径
--input-fields-terminated-by '/u0001'                   指定导出到MySQL的列检分隔符

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值