Sqoop1.4.6配置和使用

时间:2022-07-30 03:37:49

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