1. 程式人生 > >sqoop安裝和使用

sqoop安裝和使用

如果不想寫專門的HDFS入庫程式,或者HIVE的入庫程式時,可以使用apache下sqoop工具

安裝比較簡單,從apache映象中下載下來sqoop解壓後即可使用,記得將驅動的jar包copy到sqoop/lib下,注意叢集必須是開啟的。

apache映象地址:

http://archive.apache.org/dist/

使用sqoop也有一定的缺陷,比如需要匯入的HDFS資料只是一部分可用,或者中間的資料出錯,都會對結果造成影響,所以,如果對資料精準要求很高的場景,不適合使用sqoop,但是在像關係型資料庫,匯入資料到HDFS或者hive的時候確實是一大有力工具。

<span style="font-family:Microsoft YaHei;">解壓命令 tar -zxvf sqoop-xxx.tar.gz </span>
<span style="font-family:Microsoft YaHei;">
</span>
<span style="font-family:Microsoft YaHei;">使用 ,以下是從貼吧中整理出來的內容,比較全面


1)列出mysql資料庫中的所有資料庫
sqoop list-databases –connect jdbc:mysql://localhost:3306/ –username root –password root


2)連線mysql並列出test資料庫中的表
sqoop list-tables –connect jdbc:mysql://localhost:3306/test –username root –password root命令中的test為mysql資料庫中的test資料庫名稱 username password分別為mysql資料庫的使用者密碼


3)將關係型資料的表結構複製到hive中,只是複製表的結構,表中的內容沒有複製過去
sqoop create-hive-table –connect jdbc:mysql://localhost:3306/test –table sqoop_test –username root –password 123456 –hive-table test 其中 –table sqoop_test為mysql中的資料庫test中的表 –hive-table test 為hive中新建的表名稱


4)從關係資料庫匯入檔案到hive中
sqoop import –connect jdbc:mysql://localhost:3306/zxtest –username root –password 123456 –table sqoop_test –hive-import –hive-table s_test -m 1


5)將hive中的表資料匯入到mysql中,在進行匯入之前,mysql中的表
hive_test必須已經提起建立好了。 sqoop export –connect jdbc:mysql://localhost:3306/zxtest –username  root –password root –table hive_test –export-dir /user/hive/warehouse/new_test_partition/dt=2012-03-05


6)從資料庫匯出表的資料到HDFS上檔案 ./sqoop import –connect jdbc:mysql://10.28.168.109:3306/compression –username=hadoop –password=123456 –table HADOOP_USER_INFO -m 1 –target-dir /user/test 


7)從資料庫增量匯入表資料到hdfs中 ./sqoop import –connect jdbc:mysql://10.28.168.109:3306/compression –username=hadoop –password=123456 –table HADOOP_USER_INFO -m 1 –target-dir /user/test  –check-column id –incremental append –last-value 3 

</span>