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
# 计划任务