mysql导入hdfs指定位置_sqoop数据导入命令 (sql---hdfs)

本文详细介绍了如何使用Sqoop将MySQL数据导入HDFS,包括全表导入、限制条件导入、自定义SQL导入、增量导入等不同场景的操作步骤,同时涵盖了Sqoop作业的创建、查看、删除和执行。此外,还讨论了将数据从MySQL直接导入Hive的用法。
摘要由CSDN通过智能技术生成

mysql------->hdfs

sqoop导入数据工作流程:

sqoop提交任务到hadoop------>hadoop启动mapreduce------->mapreduce通过指定参数到表中获取导入的数据------->MapReduce将需导入的数据导入到HDFS中

1.全表导入:

mysql----->hdfs

sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  -m  1

#-m 1  表示指定一个任务去执行

2.限制数据范围导入:

mysql----->hdfs

sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --columns   'id,name'   --where  'id>20'   -m  1

#  --columns    指定列      --where '条件'  指定条件

3、自由sql语句导入:  (使用sql查询语句导入)

mysql----->hdfs

sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --query  'select id,name from input where id>20 and \$CONDITIONS'  -m  1

4.增量导入:持续将新增源数据导入到目标存储位置

mysql----->hdfs

#核心参数:  -check-column  #指定检索列、   --last-value  #(指定导入检索数字)  、 -incremental   #(指定导入模式)

1>append模式:   只对数据进行附加,不支持更改

sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --check-column id   --last-value  264  --incremental   append   -m 1

2>lastmodified :   适用于对源数据进行更改,对于变动数据收集,必须记录变动时间

sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --check-column last_mod     --last-value  '2018-02-02 21:35:01'  --incremental   lastmodified    -m  1  --append

#时间为最大的时间

mysql------>hive

Sqoop常用命令:

全表导入:

1.创建job:

#解释:这个job是将mysql的表导入到hive中,过程为:  mysql--àHDFS--àhive

--password-file hdfs://user/mnt/.password.file  这是指定hdfs目录下文件位置

--password-file file:///home/.test   这是指定linux服务器目录下文件位置

[root@hdoop2 hadoop]# sqoop job --create  erp4  -- import --connect jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test  --table erp_project_obversion_detail --target-dir /test3  --hive-import --hive-table erp_project_obversion_detail  --hive-overwrite -m 1

2.查看job列表:

[root@hdoop2 hadoop]#  sqoop job  --list

3.查看某个job的详细信息:

[root@hdoop2 hadoop]#  sqoop job --show erp4

#erp4为job的名称

4.删除job:

[root@hdoop2 hadoop]# sqoop job --delete erp4

5.执行job:

[root@hdoop2 hadoop]# sqoop job --exec erp4

全表导入2:一条命令

mysql数据----->hdfs【会生成一个临时文件,导入完成会自动删除】------------>hive【目标表不存在会自动创建】

sqoop import --connect jdbc:mysql://192.168.18.16:3306/database --username root --password 123456 --table name_a  --target-dir /service/name_a  --hive-import --hive-database database --hive-table name_a --fields-terminated-by ',' -m 1

增量导入:持续将新增源数据导入到目标存储位置

Mysql--àhive

1.创建job:

[root@hdoop2 hadoop]# sqoop  job --create insert1 --  import  --connect  jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test     --table  erp_project_obversion_detail  --target-dir  /test4    --hive-import --hive-table erp_project_obversion_detail   --check-column id   --last-value  264  --incremental   append   -m 1

自由查询语句导入:

1.创建job:

[root@hdoop2 hadoop]# sqoop job --create  erp1  -- import --connect jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test   --target-dir /test10   --hive-import --hive-table erp_project_obversion_detail --hive-overwrite   --query 'select * from erp_project_obversion_detail where id < 265  and  $CONDITIONS '  -m 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值