前提
安装Sqoop的前提是已经具备Java和Hadoop的环境。
准备安装包
- 下载地址:http://mirrors.hust.edu.cn/apache/sqoop/1.4.6/
或者https://download.csdn.net/download/qq_41489540/13072240 - 上传安装包sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz到虚拟机中
- 解压sqoop安装包到指定目录,
我解压到/root/soft目录下面了 ,解压命令
[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 目录下面,重命名一下配置文件
mv sqoop-env-template.sh sqoop-env.sh
修改sqoop-env.sh配置文件
export HADOOP_COMMON_HOME=$HADOOP_HOMEexport HADOOP_MAPRED_HOME=$HADOOP_HOMEexport HIVE_HOME=$HIVE_HOMEexport ZOOKEEPER_HOME=/opt/module/zookeeper-3.4.10export ZOOCFGDIR=/opt/module/zookeeper-3.4.10/confexport 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的版本是多少.
验证Sqoop
在Sqoop安装的根目录执行 bin/sqoop help 命令验证一下 , 出现警告信息不要紧,只要不是error就行.
[root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]# bin/sqoop help# 这个意思是$HBASE_HOME没配置好,我本机没HBase,所以没配置这个Warning: /opt/module/hbase-1.3.1 does not exist! HBase imports will fail.Please set $HBASE_HOME to the root of your HBase installation.# 这个也是一样Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../hcatalog does not exist! HCatalog jobs will fail.Please set $HCAT_HOME to the root of your HCatalog installation.# 这个和HBase一样Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../accumulo does not exist! Accumulo imports will fail.Please set $ACCUMULO_HOME to the root of your Accumulo installation.Warning: /opt/module/zookeeper-3.4.10 does not exist! Accumulo imports will fail.Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.20/10/29 13:47:45 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6usage: 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 HDFSimport-mainframe Import datasets from a mainframe server 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.
测试能否连接MySQL数据库
zjj101是我配置host映射的ip
在 根目录下面执行 bin/sqoop list-databases —connect jdbc:mysql://zjj101:3306/ —username root —password root
[root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]# bin/sqoop list-databases --connect jdbc:mysql://zjj101:3306/ --username root --password rootWarning: /opt/module/hbase-1.3.1 does not exist! HBase imports will fail.Please set $HBASE_HOME to the root of your HBase installation.Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../hcatalog does not exist! HCatalog jobs will fail.Please set $HCAT_HOME to the root of your HCatalog installation.Warning: /root/soft/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin/../../accumulo does not exist! Accumulo imports will fail.Please set $ACCUMULO_HOME to the root of your Accumulo installation.Warning: /opt/module/zookeeper-3.4.10 does not exist! Accumulo imports will fail.Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.20/10/29 13:51:31 INFO sqoop.Sqoop: Running Sqoop version: 1.4.620/10/29 13:51:31 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.# 说明连接MySQL了20/10/29 13:51:32 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.information_schemahivemysqlperformance_schema[root@zjj101 sqoop-1.4.6.bin__hadoop-2.0.4-alpha]#
