前提

安装Sqoop的前提是已经具备Java和Hadoop的环境。

准备安装包

  1. 下载地址:http://mirrors.hust.edu.cn/apache/sqoop/1.4.6/
    或者https://download.csdn.net/download/qq_41489540/13072240
  2. 上传安装包sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz到虚拟机中
  3. 解压sqoop安装包到指定目录,

我解压到/root/soft目录下面了 ,解压命令

  1. [root@zjj101 soft]# tar -zxvf sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz

重命名配置文件

Sqoop的配置文件与大多数大数据框架类似,在sqoop根目录下的conf目录中。

cd 到 /sqoop-1.4.6.bin__hadoop-2.0.4-alpha/conf 目录下面,重命名一下配置文件

  1. mv sqoop-env-template.sh sqoop-env.sh

修改sqoop-env.sh配置文件

  1. export HADOOP_COMMON_HOME=$HADOOP_HOME
  2. export HADOOP_MAPRED_HOME=$HADOOP_HOME
  3. export HIVE_HOME=$HIVE_HOME
  4. export ZOOKEEPER_HOME=/opt/module/zookeeper-3.4.10
  5. export ZOOCFGDIR=/opt/module/zookeeper-3.4.10/conf
  6. export HBASE_HOME=/opt/module/hbase-1.3.1

拷贝JDBC驱动

准备mysql-connector-java-5.1.27-bin.jar 拷贝到
sqoop-1.4.6.bin__hadoop-2.0.4-alpha/lib/ ,具体jar版本看你要连接的MySQL的版本是多少.

jar包下载地址1积分

验证Sqoop

在Sqoop安装的根目录执行 bin/sqoop help 命令验证一下 , 出现警告信息不要紧,只要不是error就行.

  1. [root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]# bin/sqoop help
  2. # 这个意思是$HBASE_HOME没配置好,我本机没HBase,所以没配置这个
  3. Warning: /opt/module/hbase-1.3.1 does not exist! HBase imports will fail.
  4. Please set $HBASE_HOME to the root of your HBase installation.
  5. # 这个也是一样
  6. Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../hcatalog does not exist! HCatalog jobs will fail.
  7. Please set $HCAT_HOME to the root of your HCatalog installation.
  8. # 这个和HBase一样
  9. Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../accumulo does not exist! Accumulo imports will fail.
  10. Please set $ACCUMULO_HOME to the root of your Accumulo installation.
  11. Warning: /opt/module/zookeeper-3.4.10 does not exist! Accumulo imports will fail.
  12. Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
  13. 20/10/29 13:47:45 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
  14. usage: sqoop COMMAND [ARGS]
  15. Available commands:
  16. codegen Generate code to interact with database records
  17. create-hive-table Import a table definition into Hive
  18. eval Evaluate a SQL statement and display the results
  19. export Export an HDFS directory to a database table
  20. help List available commands
  21. import Import a table from a database to HDFS
  22. import-all-tables Import tables from a database to HDFS
  23. import-mainframe Import datasets from a mainframe server to HDFS
  24. job Work with saved jobs
  25. list-databases List available databases on a server
  26. list-tables List available tables in a database
  27. merge Merge results of incremental imports
  28. metastore Run a standalone Sqoop metastore
  29. version Display version information
  30. See 'sqoop help COMMAND' for information on a specific command.

测试能否连接MySQL数据库

zjj101是我配置host映射的ip

在 根目录下面执行 bin/sqoop list-databases —connect jdbc:mysql://zjj101:3306/ —username root —password root

  1. [root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]# bin/sqoop list-databases --connect jdbc:mysql://zjj101:3306/ --username root --password root
  2. Warning: /opt/module/hbase-1.3.1 does not exist! HBase imports will fail.
  3. Please set $HBASE_HOME to the root of your HBase installation.
  4. Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../hcatalog does not exist! HCatalog jobs will fail.
  5. Please set $HCAT_HOME to the root of your HCatalog installation.
  6. Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../accumulo does not exist! Accumulo imports will fail.
  7. Please set $ACCUMULO_HOME to the root of your Accumulo installation.
  8. Warning: /opt/module/zookeeper-3.4.10 does not exist! Accumulo imports will fail.
  9. Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
  10. 20/10/29 13:51:31 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
  11. 20/10/29 13:51:31 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
  12. # 说明连接MySQL了
  13. 20/10/29 13:51:32 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
  14. information_schema
  15. hive
  16. mysql
  17. performance_schema
  18. [root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]#