mysql数据导入hive

利用 sqoop 将线上mysql表导入hive的模板代码如下:

 

 source /etc/profile;
    sudo -uflightdev sqoop import  \
    --connect jdbc:mysql://127.0.0.1:3306/%(mysql_db)s?tinyInt1isBit=false  \
    --username XXX  \
    --password XXX  \
    --table %(mysql_table)s  \
    --columns %(columns)s  \
    --where " %(update_key)s>='%(start_date)s' AND %(update_key)s<='%(end_date)s' "  \
    --hive-import  \
    --hive-overwrite  \
    --hive-partition-key dt  \
    --hive-partition-value %(yesterday)s  \
    --hive-table f_fuwu.%(hive_table)s  \
    --hive-drop-import-delims  \
    --fields-terminated-by '%(fields_terminated)s'  \
    --lines-terminated-by '\n'  \
    --null-string '\\\\N'  \
    --null-non-string '\\\\N'  \
    -m 6
  ''' % {'mysql_db': argv_dict['mysql_db'], 'mysql_table': argv_dict['mysql_table'],
         'columns': argv_dict['columns'], 'hive_table': argv_dict['hive_table'],
         'update_key': argv_dict['update_key'],
         'start_date': argv_dict['start_date'], 'end_date': argv_dict['end_date'],
         'yesterday': argv_dict['yesterday'], 'fields_terminated': argv_dict['fields_terminated']}
run_shell(sqoop_cmd)

最后run_shell(sqoop_cmd)执行脚本。

以上:mysql_table表示要导入的mysql表名,hive_table表示要导入的hive表,dt是分区字段,columns表示要导入的列,update_key表示抽取字段。

你可能感兴趣的:(大数据)