## 1、下載
```
http://sqoop.apache.org/
https://mirrors.tuna.tsinghua.edu.cn/apache/sqoop/1.4.7/
```
對于sqoop-1.4.x.tar.gz軟件包,從1.4.5開始以后版本安裝包的lib下就已經沒有了sqoop-1.4.x.jar啦,我們這里需要下載sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz。
```
[root@node1 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/sqoop/1.4.7/sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
[root@node1 ~]# tar -zxvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
```
## 2、配置
### 進入目錄
```
[root@node1 ~]# cd sqoop-1.4.7
[root@node1 sqoop-1.4.7]# ls
bin CHANGELOG.txt conf ivy lib NOTICE.txt README.txt sqoop-patch-review.py src
build.xml COMPILING.txt docs ivy.xml LICENSE.txt pom-old.xml sqoop-1.4.7.jar sqoop-test-1.4.7.jar testdata
[root@node1 sqoop-1.4.7]#
```
### 編輯配置文件
```
[root@node1 sqoop-1.4.7]# vi bin/configure-sqoop
```
* 這里應該要配置一些環境變量,比如zookeeper,hbase,現在暫時不用。
## 3、測試MySQL數據庫
### 1復制驅動程序
```
[root@node1 mysql-connector-java-5.1.46]# cp mysql-connector-java-5.1.46-bin.jar /opt/sqoop-1.4.7/lib/
```
### 3.測試連接
```
[root@node1 sqoop-1.4.7]# bin/sqoop list-databases --connect jdbc:mysql://node3:3306/ --username root --password 123456
18/04/03 10:34:56 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
18/04/03 10:34:56 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
18/04/03 10:34:56 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
information_schema
hive
mysql
performance_schema
test
webMagic
[root@node1 sqoop-1.4.7]#
```
### 3.從hdfs導入mysql
~~~
sqoop export --connect jdbc:mysql://192.168.2.101:3306/FlowDB --table WorkTable_hdfs --username root --password root --export-dir /user/jzyc/WorkTable/ --input-fields-terminated-by ','
~~~
* 這里是默認的導出模式,還有幾種導出模式請查資料。
* --export-dir 是要導出的hdfs中的文件位置。
### 4.導出后中文亂碼問題
[中文亂碼問題](https://www.cnblogs.com/wang9911-00/p/12456530.html)