1:创建shell脚本
1 touch sqoop_options.sh2 chmod 777 sqoop_options.sh
编辑文件 特地将执行map的个数设置为变量 测试 可以java代码传参数 同时也验证sqoop的 options 属性支持这种写法
1 #!/bin/bash2 /opt/cdh-5.3.6/sqoop-1.4.5-cdh5.3.6/bin/sqoop --options-file /opt/cdh-5.3.6/sqoop-1.4.5-cdh5.3.6/sqoop-import-mysql.txt --num-mappers $1
3 if [ $? -eq 0];then4 echo "success"
5 else
6 echo "error"
7 fi
2:创建 sqoop-import-mysql.txt 文件并编辑
touch sqoop-import-mysql.txt
1 export2 --connect3 jdbc:mysql://172.16.71.27:3306/babasport
4 --username5 root6 --password7 root8 --table9 test_hive10 --export-dir11 /user/hive/warehouse/hive_bbs_product_snappy12 --input-fields-terminated-by13 '\t'
hive数据存在hdfs位置
3:开始写java后台代码 目前只支持 window写法 后期加上linux调用shell脚本的写法
1 packagecom.liveyc.common.utils;2
3 importjava.util.Properties;4
5 importorg.apache.commons.logging.Log;6 importorg.apache.commons.logging.LogFactory;7
8 public classFileToHbase {9 /**
10 * shell脚本执行成功标识11 */
12 public static int SHELL_EXIT_OK = 0;13 public static Log log = LogFactory.getLog(FileToHbase.class);14 public static String connIp = "172.16.71.120";15 public static String connUser = &#