zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Codeforces 525C Om Nom and Candies 枚举 + 复杂度分析
    Codeforces 526B Om Nom and Dark Park 树形dp
    Codeforces 526A King of Thieves 枚举
    Regionals 2014 Asia
    Regionals 2014 Asia
    access数据库和sqlsever数据库sql语句的布尔值boolean的写法
    取消阴影行
    引用其他单元的2种方法
    选中阴影行
    全选
  • 原文地址:https://www.cnblogs.com/tudousiya/p/11241275.html
Copyright © 2011-2022 走看看