什么是Sqoop
- 数据交换工具(ETL):RDBMS(MySQL、Oracle等)<-->Sqoop<-->HDFS(HBase、Hive等)
- 基于JDBC
- 执行数据交换时,本质是执行一个MapReduce
安装
- tar -zxvf sqoop-1.4.5.bin__hadoop-0.23.tar.gz -C ~/training/
- 设置环境变量
- vi ~/.bash_profile
命令
- codegen:将关系数据库表映射为一个Java文件,Java class类,及相关的jar包
- sqoop codegen --connect jdbc:oracle:thin:@192.168.174.133:1521/orcl --username SCOTT --password tiger --table EMP --outdir /root/temp
- 由于是基于 jdbc 访问数据库,需要把 oracle 的 jdbc jar 包放到 sqoop 的 lib 目录下
- C:oracleproduct10.2.0db_1jdbclibojdbc14.jar
- create-hive-table:将关系型数据库的表结构复制到hive中
- sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --table username --username root --password 123456 --hive-table test
- eval:在sqoop中执行SQL语句
- sqoop eval --connect jdbc:oracle:thin:@192.168.174.133:1521/orcl --username SCOTT --password tiger --query 'select * from emp'
- import:将数据库表的数据导入HDFS中
- 导入EMP表
- 底层是MapReduce任务
- sqoop import --connect jdbc:oracle:thin:@192.168.174.133:1521/orcl --username SCOTT --password tiger --table EMP --target-dir /sqoop/import/emp1
- 导入EMP表
-
- 导入指定列
- sqoop import --connect jdbc:oracle:thin:@192.168.174.133:1521/orcl --username SCOTT --password tiger --table EMP --columns EMPNO,ENAME,SAL --target-dir /sqoop/import/emp2
- 导入订单表(约92万数据)
- 注意表名大写
- 30826876/1024/1024=29.4 M
- sqoop import --connect jdbc:oracle:thin:@192.168.174.133:1521/orcl --username SH --password sh --table SALES --target-dir /sqoop/import/sales -m 1
- 导入指定列
- 其他命令
参考
Sqoop 安装和基本操作
https://blog.csdn.net/yumingzhu1/article/details/80678525
https://www.cnblogs.com/mmzs/p/8149921.html
Windows 不能在本地计算机启动 OracleDBConsoleorcl的问题解决方法