hive 数据管理

hive管理

创建数据库

web sql

DROP DATABASE  IF EXISTS  test;
# 先删表再删库
DROP TABLE IF EXISTS default.`user`
# 删除默认库下的user表
select * from  test.table order by id DESC limit 1;
#查看最后一条记录

sqoop 导入mysql数据

/root/sqoop/sqoop.sh

#!/bin/bash
# --------------------------------------------------
#Author:  LJ
#Email:   admin@attacker.club

#Last Modified: 2018-10-23 11:38:54
#Description:
# --------------------------------------------------
. /etc/profile
#载入环境变量


host=10.0.1.254
user=root
passwd="xxxxxxx"
database="rec_log"
table="rec_log_all"
hivedatabase="rec_log"
hivetable="rec_log_all"
#hivedatabase="test"
#hivetable="log_all"

check_field="gmt_modify"
Uniqueid="id"
Yesterday=$(date -d -1day +%Y-%m-%d)



List()
{
    sqoop list-databases  \
    --connect jdbc:mysql://${host}:3306/ \
    --username ${user} \
    --password ${passwd}
}


New_sqoop ()
{
    sqoop import \
    --connect jdbc:mysql://${host}:3306/${database} \
    --username ${user} \
    --password ${passwd} \
    --table ${table}  \
    --hive-import  \
    --hive-table  ${hivetable} \
    --hive-database  ${hivedatabase} \
    --create-hive-table \
    --null-string 'null' \
    --null-non-string 'null' \
    --hive-overwrite \
    --fields-terminated-by "\t" --lines-terminated-by "\n" --as-textfile \
    --delete-target-dir

# hive-import 插入数据到hive当中,使用hive的默认分隔符
# hive-table 指定hive当中的表名
# create-hive-table 建表,如果表已经存在,该操作会报错
# hive-overwrite  重写插入
}

Sqoop_yesterday()
{
     sqoop import \
    --connect jdbc:mysql://${host}:3306/${database} \
    --username ${user} \
    --password ${passwd} \
    --table ${table}  \
    --hive-import  \
    --hive-table  ${hivetable} \
    --hive-database  ${hivedatabase} \
    --null-string 'null' \
    --null-non-string 'null' \
    --fields-terminated-by "\t" --lines-terminated-by "\n" --as-textfile \
    --merge-key ${Uniqueid} \
    --check-column ${check_field} \
    --incremental append  \
    --last-value "${Yesterday} 04:00:00"
# hdfs 50070服务可浏览文件目录`
# 指定库 --hive-database zabbix 
# merge-key 唯一键
# check-column 检验字段 last-value 时间或者自增id到当前
# append 增量追加
}

Begin_time=`date +"%Y年%m月%d日 %H:%M:%S"`

List
Sqoop_yesterday
# 昨天数据

#New_sqoop
# 全新导入

End_time=`date +"%Y年%m月%d日 %H:%M:%S"`
echo "备份跨度:"${Yesterday}"-至当前" >> /root/sqoop/result.log
echo "开始运行时间:"${Begin_time} >> /root/sqoop/result.log
echo "脚本结束时间:"${End_time} >> /root/sqoop/result.log

crontab -l

30 16 * * *   /root/sqoop/sqoop.sh > /root/sqoop/result.log
# 计划任务

转载于:https://my.oschina.net/attacker/blog/2249142

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值