http://jingpin.jikexueyuan.com/article/39333.html
http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html#_example_invocations_4
http://blog.csdn.net/panguoyuan/article/details/38871807
http://www.tutorialspoint.com/sqoop/sqoop_installation.htm
http://www.open-open.com/lib/view/open1401346410480.html
http://www.cloudera.com/documentation/enterprise/latest/topics/cdh_ig_sqoop2_configure.html
https://my.oschina.net/crxy/blog/417890
http://blog.csdn.net/lyn1539815919/article/details/52400555
http://www.cnblogs.com/xing901022/p/5920891.html
(1)安裝環境
作業系統:Linux(Ubuntu16.04)
JDK版本:1.7.0_45
Hadoop版本:hadoop2.7.0
Sqoop版本:sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz
hadoop安裝目錄:/home/hadoop/hadoop-2.7.3
Sqoop安裝目錄:/home/hadoop/sqoop-1.4.6
Hadoop和Sqoop都是同一個使用者hadoop下面,hadoop使用者的的家目錄:/home/hadoop
2)修改Sqoop配置檔案
cd /home/hadoop/sqoop-1.4.6/conf
cp sqoop-env-template.sh sqoop-env.sh
在檔案sqoop-env.sh的末尾追加如下幾個環境變數設定:
export HADOOP_COMMON_HOME=/home/hadoop/hadoop-2.7.3
export HADOOP_MAPRED_HOME=/home/hadoop/hadoop-2.7.3/share/hadoop/mapreduce
#export HIVE_HOME=/home/hadoop/hive-0.12.0
(3)修改hadoop使用者的環境變數
編輯檔案:/home/hadoop/.bash_profile,追加如下內容:
export SQOOP_HOME=/home/hadoop/sqoop-1.4.6
export PATH=$PATH:$SQOOP_HOME/bin
export LOGDIR=$SQOOP_HOME/logs
(4)將mysql的jdbc驅動程式放到$SQOOP_HOME/lib目錄下
將 mysql-connector-java-5.1.15.jar 複製到 :/home/hadoop/sqoop-1.4.5/lib目錄下
(5)試用sqoop
1 、用Sqoop來列出192.168.0.1下的資料庫
進入$SQOOP_HOME/bin目錄下執行如下命令:
# ./sqoop list-databases --connect
jdbc:mysql://192.168.0.1:3306/mydb?characterEncoding=UTF-8 --username
test --password 'test'
sqoop_test是建的database
[
mysql -u root -p
create database sqoop_test;
use sqoop_test;
create table test(var int(4));
]
./sqoop list-tables --connect jdbc:mysql://localhost/sqoop_test?characterEncoding=UTF-8 --username root --password '00'
2、將表book下的資料匯入到HDFS中去
進入$SQOOP_HOME/bin目錄下執行如下命令:
./sqoop import --connect
jdbc:mysql://192.168.0.1:3306/mydb?characterEncoding=UTF-8 --username
test --password 'test' --target-dir '/user/hive/warehouse/book' --table
book ;
./sqoop list-tables --connect jdbc:mysql://localhost/sqoop_test?characterEncoding=UTF-8 --username root --password '00'
把資料匯入到mysql
./sqoop export --connect jdbc:mysql://localhost/sqoop_test --username root --password '00' --table sqoop_t --export-dir /t/data_sqoop_test
./sqoop export --connect jdbc:mysql://localhos3306/sqoop_test --username root --password '00' --table sqoop_t --export-dir /t/data_sqoop_test