一、使用命令
psql数据库操作
#查看数据库sqoop list-databases --connect jdbc:postgresql://10.121.120.42:5432/etl_service --username postgres --password hawk@159#sqoop根据postgresql表创建hive表sqoop create-hive-table --connect jdbc:postgresql://10.121.120.42:5432/etl_service --username postgres --password hawk@159 --table aijie --hive-table aijie#psql->hivesqoop import --connect jdbc:postgresql://10.121.120.42:5432/etl_service --username postgres --password hawk@159 --table aijie -m 1 --hive-home /home/hive --hive-import --create-hive-table --hive-database prdhawk --hive-table aijie
mysql操作
sqoop --options-file xxx.sqoop
import--connectjdbc:mysql://10.161.12.98:4606/tianyan?useUnicode=true&characterEncoding=UTF-8--usernametianyan--passwordywjk@123--as-textfile--columnsid,host,monitor_time,monitor_time_begin,monitor_time_end--tablealarm_host--fields-terminated-by'\001'--delete-target-dir--target-dir/apps/hive/warehouse/tianyan.db/sqoop/alarm_host_data-m1--hive-home/home/hive--hive-import--create-hive-table--hive-databasetianyan--hive-tablealarm_host
import--connectjdbc:mysql://node1:3306/songresult?dontTrackOpenResources=true&defaultFetchSize=10000&useCursorFetch=true&useUnicode=yes&characterEncoding=utf8 --usernameroot--password123--tablesong--target-dir/user/hive/warehouse/data/song/TO_SONG_INFO_D/--delete-target-dir--num-mappers1--hive-import--hive-databasespark--hive-overwrite--fields-terminated-by'\t'--hive-tableTO_SONG_INFO_D
oracle操作
sqoop import --connect jdbc:oracle:thin:@10.96.80.188:1521:PRDMDMN1 --username PRDHAWK --password PRDHAWK0827 --table PRDHAWK.ADDRESS -m 1 --hive-home /home/hive --hive-import --create-hive-table --hive-database prdhawk --hive-table address
17/05/02 18:15:47 ERROR tool.ImportTool: Imported Failed: There is no column found in the target table tysecdb.secsight_config_count. Please ensure that your table name is correct
sqoop导入到出时 对应RDBMS数据库的表名必须大写 不支持小写。
二、安装配置
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/sqoop/1.4.7/
1、把sqoop-1.4.7.binhadoop-2.6.0.tar.gz上传到linux
2、解压sqoop-1.4.7.binhadoop-2.6.0.tar.gz到/opt/module/目录下
tar -zxvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz -C /opt/module/cd /opt/module/mv sqoop-1.4.7.bin__hadoop-2.6.0/ sqoop
3、修改/opt/module/sqoop/conf目录下的sqoop-env-template.sh名称为sqoop-env.sh
mv sqoop-env-template.sh sqoop-env.sh#配置sqoop-env.sh文件vim sqoop-env.sh#根据实际情况填写export HADOOP_COMMON_HOME=/opt/module/hadoop-2.7.2export HADOOP_MAPRED_HOME=/opt/module/hadoop-2.7.2export HIVE_HOME=/opt/module/hiveexport HIVE_CONF_DIR=/opt/module/hive/confexport ZOOKEEPER_HOME=/opt/module/zookeeper-3.4.10export ZOOCFGDIR=/opt/module/zookeeper-3.4.10export HADOOP_COMMON_HOME=/apache/hadoopexport HADOOP_MAPRED_HOME=/apache/hadoopexport HIVE_HOME=/apache/hiveexport ZOOKEEPER_HOME=/usr/local/apache-zookeeper-3.6.3-binexport ZOOCFGDIR=/usr/local/apache-zookeeper-3.6.3-binexport HIVE_CONF_DIR=/apache/hive/conf
4、链接数据库需要添加JDBC驱动
/opt/module/sqoop/lib/
5、添加hive驱动
cp -p /apache/hive/lib/hive-common-2.2.0.jar /opt/module/sqoop/lib/
6、添加环境变量
export SQOOP_HOME=/opt/module/sqoopexport ZOOKEEPER_HOME=/usr/local/apache-zookeeper-3.6.3-binexport PATH=/apache/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/apache/hadoop/bin:/apache/hadoop/sbin:/apache/scala/bin:/apache/spark/bin:/apache/hive/bin:/apache/livy/bin:/bin:/bin:/opt/module/sqoop/bin:/usr/local/apache-zookeeper-3.6.3-bin/binexport HIVE_CONF_DIR=/apache/hive/conf
