Sqoop是Apache旗下的一个开源框架,专门用来做数据的导入和导出。
Sqoop的安装非常简单,只需要把下载下来的tar包解压设置两个环境变量就可以了
1.安装部署
下载版本:sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz
官网:http://mirror.bit.edu.cn/apache/sqoop/1.4.6/
1.1把tar包解压到/usr/sqoop
tar -xvzf sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz /usr/ //解压到指定路径 mv sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz sqoop //重命名,可选可不选
1.2设置环境变量
把Sqoop添加到PATH文件, vim /etc/profile ,设置
export SQOOP_HOME=/usr/sqoop export PATH=$PATH:$SQOOP_HOME/bin
因为Sqoop需要用到hadoop下面的jar包进行操作,所以需要设置HADOOP_COMMON_HOME 来指明hadoop安装在那个目录下。
[[email protected] ~]# export HADOOP_COMMON_HOME=/usr/hadoop //指明hadoop安装路径
[[email protected] ~]# export HADOOP_MAPRED_HOME=/usr/hadoop //因为hadoop最终把它的作业转换成mapreduce进行提交执行,实际上和hadoop home目录相同
也可以用另一种方式,配置sqoop/conf目录下的sqoop-env.sh
vim sqoop-env.sh
把jdbc驱动包放到sqoop的lib目录下,如果里面有就不需要加(里面有个MySQL驱动包)。
1.3验证安装完成
输入 sqoop help ,如下面所示,表示安装正常,另,没有设置PATH变量的需要到sqoop/bin执行 ./sqoop help
[[email protected] ~]# sqoop help Warning: /usr/sqoop/../hcatalog does not exist! HCatalog jobs will fail. Please set $HCAT_HOME to the root of your HCatalog installation. Warning: /usr/sqoop/../accumulo does not exist! Accumulo imports will fail. Please set $ACCUMULO_HOME to the root of your Accumulo installation. 17/08/12 03:49:43 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6 usage: sqoop COMMAND [ARGS] Available commands: codegen Generate code to interact with database records create-hive-table Import a table definition into Hive eval Evaluate a SQL statement and display the results export Export an HDFS directory to a database table help List available commands import Import a table from a database to HDFS import-all-tables Import tables from a database to HDFS import-mainframe Import datasets from a mainframe server to HDFS job Work with saved jobs list-databases List available databases on a server list-tables List available tables in a database merge Merge results of incremental imports metastore Run a standalone Sqoop metastore version Display version information See ‘sqoop help COMMAND‘ for information on a specific command.
2.使用Sqoop进行数据迁移
下面通过6个例子展示使用Sqoop进行数据迁移
2.1使用Sqoop导入MySQL数据到HDFS
[[email protected] ~]# sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password root --table user --columns ‘uid,uname‘ -m 1 -target-dir ‘/sqoop/user‘; //-m 指定map进程数,-target-dir指定存放目录
2.2
时间: 2024-10-11 05:40:14