sqoop 基本使用

一、把MySQL数据导入到hdfs:

sqoop import \
--connect jdbc:mysql://192.168.83.11:3306/sqoop \
--username root \
--password Oracle123 \
--table sqoop1 \
--delete-target-dir \
-m 1

--query 指明查询的sql语句,注意主里加了一个 and \$conditions ,这是必需的,若是有带where条件的话mysql

--hive-table 指明目标表名sql

--target-dir 指明目标表的hdfs路径oop

--delete-target-dir 删除目标hfds路径数据spa

--split-by 指明shuffle的字段,通常是取主键code

--hive-overwrite 先删除旧数据,再从新插入字符串

--null-string --对null字符串和处理,映射成hive里的nullget

--null-non-string --对null非字符串和处理,映射成hive里的nullstring

二、把hdfs数据导入到MySQL:

先建立表结构,(感受sqoop在这里作的至关很差,表结构不能本身建立吗?)it

create table emp_1
          (empno int,
          ename varchar(20),
          job varchar(20),
          mgr int,
          hirdate varchar(20),
          sal double,
          comm double,
          deptno int);

在导入数据io

sqoop export --connect jdbc:mysql://hd1:3306/hive --username root --password Oracle123 --table emp_1 --export-dir /user/hive/warehouse/part_emp3/mgr=10/emp.txt --fields-terminated-by '\t'

 

三、将MySQL的表结构复制到hive中

sqoop create-hive-table --connect jdbc:mysql://hd1:3306/hive --table TBS --username root --password Oracle123 --hive-table test
相关文章
相关标签/搜索