sqoop簡單用法

2021-06-21 06:54:05 字數 1167 閱讀 7294

sqoop是用於對資料進行匯入匯出的。

(1)把mysql、oracle等資料庫中的資料匯入到hdfs、hive、hbase中

(2)把hdfs、hive、hbase中的資料匯出到mysql、oracle等資料庫中

1.把資料從mysql匯入到hdfs(預設是/user/)中

件,--hive-import代表匯入到hdfs上的hive中。

sqoop import --connect jdbc:mysql://hadoop0:3306/hive  --username root --password admin --table tbls --fields-terminated-by

件,--hive-import代表匯入到hdfs上的hive中。再匯入時檢查tbl_id欄位,只匯入該字段值大於6的記錄。

sqoop import --connect jdbc:mysql://hadoop0:3306/hive  --username root --password admin --table tbls --fields-terminated-by

2.把資料從hdfs匯出到mysql中  

將hdfs上的根目錄上的ids資料夾內的所有檔案(匯出都是按目錄匯出,不是按檔案),匯出到ids表中。

sqoop export --connect jdbc:mysql://hadoop0:3306/hive  --username root --password admin --table ids --fields-terminated-by

'\t' --export-dir '/ids'

3.設定為作業,執行作業

將該指令碼儲存為乙個名為myjpb的job,方便使用。以後直接執行myjob即可。

可以通過sqoop job --list 檢視。

執行myjob的命令:sqoop job --exec myjob 執行需要設定執行密碼,如果不想輸入需要在sqoop-site.xml中將以下注釋的配置放開。

如果使用預設的map任務數量(4個),那代表同時有四個事務。如果想保持四個事務的一致性,可以使用 --staging-table 指定乙個表名,將資料先全部匯入到該錶後,再進行匯入匯出操作,這樣就可以滿足多事務的一直。操作完成後清空該錶還可以使用 --clear-staging-table 引數

mysql的簡單用法 mysql簡單用法

刪除使用者 drop user jack drop比delete刪除的優勢在於drop可以刪除使用者的許可權,更加徹底 更改使用者名稱 rename user jack to jacknew 使用者的都存在與user表中,更改名稱,許可權不變 更改使用者密碼 update mysql.user se...

oracle cursor 簡單用法

procedure changespecialdiscount compid in invarchar2 ccid in invarchar2 cono in invarchar2 is sum cc all number 14 4 0 wsp disc number 14 4 wspcl disc...

Oracle Trigger簡單用法

1.trigger 是自動提交的,不用commit,rollback 2.trigger最大為32k,如果有複雜的應用可以通過在trigger裡呼叫procedure或function來實現。3.語法 create or replace trigger on declare begin except...