sqoop數據導入命令 (sql---hdfs)


mysql------->hdfs

sqoop導入數據工作流程:

sqoop提交任務到hadoop------>hadoop啟動mapreduce------->mapreduce通過指定參數到表中獲取導入的數據------->MapReduce將需導入的數據導入到HDFS中

1.全表導入:

mysql----->hdfs

    sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  -m  1

#-m 1  表示指定一個任務去執行 

2.限制數據范圍導入:

mysql----->hdfs

   sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --columns   'id,name'   --where  'id>20'   -m  1

#  --columns <列名>   指定列      --where '條件'  指定條件 

 

3、自由sql語句導入:  (使用sql查詢語句導入)

mysql----->hdfs

       sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --query  'select id,name from input where id>20 and \$CONDITIONS'  -m  1

 

4.增量導入:持續將新增源數據導入到目標存儲位置

mysql----->hdfs

#核心參數:  -check-column  #指定檢索列、   --last-value  #(指定導入檢索數字)  、 -incremental   #(指定導入模式)

1>append模式:   只對數據進行附加,不支持更改

      sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --check-column id   --last-value  264  --incremental   append   -m 1

2>lastmodified :   適用於對源數據進行更改,對於變動數據收集,必須記錄變動時間

   sqoop  import  --connect  jdbc:mysql://192.168.122.15:3306/company  --username  hivee  --password 123456 --table  card  --target-dir  '/input'   --check-column last_mod     --last-value  '2018-02-02 21:35:01'  --incremental   lastmodified    -m  1  --append

#時間為最大的時間

 

 

mysql------>hive

Sqoop常用命令:

 

全表導入:

1.創建job:

#解釋:這個job是將mysql的表導入到hive中,過程為:  mysql--àHDFS--àhive

 --password-file hdfs://user/mnt/.password.file  這是指定hdfs目錄下文件位置

--password-file file:///home/.test   這是指定linux服務器目錄下文件位置

[root@hdoop2 hadoop]# sqoop job --create  erp4  -- import --connect jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test  --table erp_project_obversion_detail --target-dir /test3  --hive-import --hive-table erp_project_obversion_detail  --hive-overwrite -m 1

 

2.查看job列表:

[root@hdoop2 hadoop]#  sqoop job  --list

 

 

3.查看某個job的詳細信息:

[root@hdoop2 hadoop]#  sqoop job --show erp4   

#erp4為job的名稱

 

4.刪除job:

[root@hdoop2 hadoop]# sqoop job --delete erp4

 

5.執行job:

[root@hdoop2 hadoop]# sqoop job --exec erp4

 

 

 全表導入2:一條命令
mysql數據----->hdfs【會生成一個臨時文件,導入完成會自動刪除】------------>hive【目標表不存在會自動創建】
sqoop import --connect jdbc:mysql://192.168.18.16:3306/database --username root --password 123456 --table name_a  --target-dir /service/name_a 1 --hive-import --hive-database database --hive-table name_a --fields-terminated-by ',' -m 1

 

 

 

增量導入:持續將新增源數據導入到目標存儲位置

Mysql--àhive

 

1.創建job:

[root@hdoop2 hadoop]# sqoop  job --create insert1 --  import  --connect  jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test     --table  erp_project_obversion_detail  --target-dir  /test4    --hive-import --hive-table erp_project_obversion_detail   --check-column id   --last-value  264  --incremental   append   -m 1

 

 

 

 

 

 

 

自由查詢語句導入:

1.創建job:

[root@hdoop2 hadoop]# sqoop job --create  erp1  -- import --connect jdbc:mysql://192.168.18.72:3306/erp_product --username hive  --password-file file:///home/.test   --target-dir /test10   --hive-import --hive-table erp_project_obversion_detail --hive-overwrite   --query 'select * from erp_project_obversion_detail where id < 265  and  $CONDITIONS '  -m 1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM