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
相關文章
相關標籤/搜索