hadoop sqoop 实例

hadoop sqoop (实例)day-1

sqoop:是一款开源的工具,主要用于在Hadoop与传统的数据库(mysql)间进行数据的传递,可以将一个关系型数据库中的数据导进到Hadoop的HDFS中,也可以将HDFS的数据导进到关系型数据库中。

实例一:(从mysql中导入表HDFS)

创建脚本:vim sqoop-customer.sh

#!/bin/bash

sqoop import --connect jdbc:mysql://localhost:3306/数据库名 --table customers (customers为mysql表名) --username root --password ok --target-dir /data/user (创建导入hdfs的w文件名)

实例二:(通过where语句过滤到hdfs)

#!/bin/bash

sqoop import --connect jdbc:mysql://localhost:3306/test --table customers --where "customer_id<10" --username root --password ok --delete-target-dir (如果原文件有则删除) --target-dir /data/user/customers

实例三:(通过columns语句过滤到hdfs)

#!/bin/bash

sqoop import --connect jdbc:mysql://localhost:3306/test --table customers --columns "customer_id,customer_fname,customer_lname" --username root --password ok --delete-target-dir --target-dir /data/user/customers

实例四:(通过select语句过滤到hdfs)

#!/bin/bash

sqoop import --connect jdbc:mysql://localhost:3306/test --query "select * from customer where customer_id=1and$CONDITIONS" --username root --password ok --split-by customer_id --delete-target-dir --target-dir /data/user/customers

实例五:(append追加数据)

#!/bin/bash

sqoop import --connect jdbc:mysql://localhost:3306/test --table customers --username root --password ok --where 'customer_id<100' --incremental append --check-column customer_id --last-value 10 --target-dir /data/user/customers

原文地址:https://www.cnblogs.com/tudousiya/p/11241275.html