• hadoop-16-sqoop导入oracle数据


      sqoop = sql + hadoop

    1,系统方面的准备

    scp ./ojdbc6.jar root@server-1:/usr/hdp/2.6.0.3-8/sqoop/lib/
    scp ./ojdbc6.jar root@server-2:/usr/hdp/2.6.0.3-8/sqoop/lib/

    cd /usr/hdp/2.6.0.3-8/sqoop/lib/
    chmod 755 ojdbc6.jar

    学习了:https://www.cnblogs.com/jxhd1/p/6528574.html
    su root
    # usermod -a -G hadoop user001 '把user001用户添加到hadoop组中
    # usermod -a -G hdfs user001 '把user001用户添加到hdfs组中

    2,sqoop导入到hdfs中
    学习了:http://blog.csdn.net/yu616568/article/details/45030739

    '可行,识别--connection-manager,主要是-m 2进行并行导入
    sqoop import --connect jdbc:Oracle:thin:@127.0.0.1:1521:ora --connection-manager org.apache.sqoop.manager.OracleManager --username admin --password admin -m 2 --split-by id --query 'SELECT t.* FROM tbl01 t where $CONDITIONS' --target-dir '/user/user001/tbl01'

    '方法2 ,用--driver指定了类,-m 1 进行导入了
    sqoop import --connect jdbc:Oracle:thin:@127.0.0.1:1521:ora --username admin --password admin -m 1 --driver oracle.jdbc.driver.OracleDriver --query 'SELECT * FROM tbl02 t where 1=1 and $CONDITIONS' --target-dir '/user/user001/tbl02'

    ‘方法3 , 查看源码之后org.apache.sqoop.manager.OracleManager.OracleManager(SqoopOptions),

    '里面:    } else if (scheme.startsWith("jdbc:oracle:")) {, 注意自己的连接串写的不规范

    sqoop import --connect jdbc:oracle:thin:@127.0.0.1:1521:ddxt11 --username admin --password admin   -m 2 --split-by id --query 'SELECT t.* FROM tbl01  t where $CONDITIONS' --target-dir '/user/user001/tbl01'

     ‘方法4, 表名(TBL01)、列名(--split-by ID)都要大写,不大写就报错给你看;

    '主要是生成的sql语句:SELECT t.* FROM "TBL01" t WHERE 1=0,SELECT MIN("NAME1"), MAX("NAME1") FROM "TBL01"

    sqoop import --connect jdbc:oracle:thin:@127:1521:ddxt11 --username admin  --password admin -m 2 --split-by ID --table TBL01 --target-dir '/user/user001/tbl01'

    3,数据库表从hdfs中导入到hive中

    user001用户登录:

    >hive

    >show databases;

    >create database admin;

    >use admin;

    >create table tbl01
    (
    id bigint comment '父id',
    pid bigint comment '父id',
    name1 VARCHAR(16) comment 'a',
    name2 VARCHAR(64) comment 'b',
    )
    ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
    stored as textfile;


    在hive中执行:
    load data inpath '/user/user001/tbl01/part-m-00000' into table admin.tbl01;

    在user001用户中执行:

    必须先把表tbl01创建出来;
    hive -e "load data inpath '/user/user001/tbl01/part-m-00000' into table admin.tbl01;"
    或者
    hive -f '/websoftware/tbl01_imp.sql'

    不会报错了;需要把user001添加到hdfs组下面;
    因为hadoop fs -ls /apps/hive/warehouse 输出:
    drwxrwxrwx - user001 hdfs 0 2017-11-09 10:00 /apps/hive/warehouse/admin.db
    drwxrwxrwx - user001 hdfs 0 2017-11-02 15:14 /apps/hive/warehouse/hive_test.db
    hive存储文件的地方,需要使用hdfs组权限;


    user001用户下面:直接从hdfs下面move到hive下面;
    方法2,方法1是在hive下面使用load data 方法;
    hadoop fs -mv /user/user001/d_zmzd/part-m-00000 /apps/hive/warehouse/admin.db/tbl02

  • 相关阅读:
    00027_方法的重载
    Creating a Physical Standby Database 11g
    APUE信号-程序汇总
    随手记Swift基础和Optional Type(问号?和感叹号!)
    双十二即将来袭!阿里内部高并发系统设计手册终开源,你那系统能抗住“秒杀”吗?
    ajax初见
    编程基本功:BUG测试步骤尽可能用文档简化,突出重点
    年轻就该多尝试,教你20小时Get一项新技能
    微信小程序-封装请求基准路径、接口API 和使用
    理解Python闭包,这应该是最好的例子
  • 原文地址:https://www.cnblogs.com/stono/p/7813672.html
Copyright © 2020-2023  润新知