sqoop 脚本:
#!/bin/bash ######## sqoop_import.sh $1 $2 ####### db_date=$2 echo $db_date db_name=gmall #########该方法有两个参数 $1 $2############ import_data() { /soft/install/sqoop/bin/sqoop import \ --connect jdbc:mysql://hadoop001:3306/$db_name \ --username root \ --password root \ --target-dir /origin_data/$db_name/db/$1/$db_date \ --delete-target-dir \ --num-mappers 1 \ --fields-terminated-by "\t" \ --query "$2"' and $CONDITIONS;' } import_base_category3(){ import_data "base_category3" "select id, name, category2_id from base_category3 where 1=1" } import_order_info(){ import_data "order_info" "select id, total_amount, order_status, user_id, payment_way, out_trade_no, create_time, operate_time from order_info where (DATE_FORMAT(create_time,'%Y-%m-%d')='$db_date' or DATE_FORMAT(operate_time,'%Y-%m-%d')='$db_date')" } if[ ! "$1" ] ; then echo "pls input ags " fi
case $1 in "base_category3") import_base_category3 ;; "order_info") import_order_info ;; "all") import_base_category3 import_order_info ;; esac