Apache Sqoop是用來實現(xiàn)結(jié)構(gòu)型數(shù)據(jù)(如關(guān)系數(shù)據(jù)庫)和Hadoop之間進行數(shù)據(jù)遷移的工具。它充分利用了MapReduce的并行特點以批處理的方式加快數(shù)據(jù)的傳輸,同時也借助MapReduce實現(xiàn)了容錯。
項目地址:http://sqoop.apache.org/
目前為止,已演變出了2個版本:sqoop1和sqoop2。
sqoop1的最新版本是1.4.5,sqoop2的最新版本是1.99.3;1.99.3和1.4.5是不兼容的,并且功能還沒有開發(fā)完成,還不合適在生產(chǎn)環(huán)境部署。
sqoop支持的數(shù)據(jù)庫:
Database
|
version
|
--direct support? |
connect string matches
|
---|---|---|---|
HSQLDB | 1.8.0+ | No | jdbc:hsqldb:*// |
MySQL | 5.0+ | Yes | jdbc:mysql:// |
Oracle | 10.2.0+ | No | jdbc:oracle:*// |
PostgreSQL | 8.3+ | Yes (import only) | jdbc:postgresql:/ |
guojian@localtest:~/work$ sudo apt-get install sqoop
guojian@localtest:~/work$ sqoop help
usage: sqoop COMMAND [ARGS]Available commands:codegen Generate code to interact with database recordscreate-hive-table Import a table definition into Hiveeval Evaluate a SQL statement and display the resultsexport Export an HDFS directory to a database tablehelp List available commandsimport Import a table from a database to HDFSimport-all-tables Import tables from a database to HDFSjob Work with saved jobslist-databases List available databases on a serverlist-tables List available tables in a databasemerge Merge results of incremental importsmetastore Run a standalone Sqoop metastoreversion Display version informationSee 'sqoop help COMMAND' for information on a specific command.
import是將關(guān)系數(shù)據(jù)庫遷移到HDFS上
guojian@localtest:~/work$ sqoop import --connect jdbc:mysql://192.168.81.176/hivemeta2db --username root -password passwd --table sds
guojian@localtest:~/work$ hadoop fs -ls /user/guojian/sdsFound 5 items-rw-r--r-- 3 guojian cug_test 0 2014-09⑴1 16:04 /user/guojian/sds/_SUCCESS-rw-r--r-- 3 guojian cug_test 483 2014-09⑴1 16:03 /user/guojian/sds/part-m-00000.snappy-rw-r--r-- 3 guojian cug_test 504 2014-09⑴1 16:04 /user/guojian/sds/part-m-00001.snappy-rw-r--r-- 3 guojian cug_test 1001 2014-09⑴1 16:03 /user/guojian/sds/part-m-00002.snappy-rw-r--r-- 3 guojian cug_test 952 2014-09⑴1 16:03 /user/guojian/sds/part-m-00003.snappy
可以通過--m設(shè)置并行數(shù)據(jù),即map的數(shù)據(jù),決定文件的個數(shù)。
默許目錄是/user/${user.name}/${tablename},可以通過--target-dir設(shè)置hdfs上的目標目錄。
如果想要將全部數(shù)據(jù)庫中的表全部導(dǎo)入到hdfs上,可使用import-all-tables命令。
sqoop import-all-tables
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈