hive数据库级批量删库两种方法

本文介绍了两种在Hive中批量删除数据库的方法,包括先删除表再删除库的脚本操作方式以及直接的数据库级批量删除方法。

方法一

先删除表
batch-delete-tables.sh

#!/bin/sh
dbname=$1
hive -e "use $dbname;show tables;"| while read line
do
echo -n "drop table $line purge;">>temptables.txt
done

tables=`cat temptables.txt`
echo $tables
hive -e "use $dbname;$tables"
rm -f temptables.txt

再删库
batch-delete-databases.sh

#!/bin/sh

hive -e "show databases;"|while read line
do
	if [[ $line != "default" && ! -z $line ]];then 
	  echo -n "drop database $line;" >>tempdbs.txt
	  echo "$line" >> dbslist.txt
	fi
done

jdbs=`cat dbslist.txt`
for it in $jdbs
do
. ./batch-delete-tables.sh $it
done


dbs=`cat tempdbs.txt`
echo  $dbs
hive -e "$dbs"
rm -f tempdbs.txt dbslist.txt

两个文件放一块,运行后面一个文件就行了

方法二

#!/bin/sh

hive -e "show databases;"|while read line
do
	if [[ $line != "default" && ! -z $line ]];then 
	  echo "drop database $line cascade;" >> dbslist.txt
	fi
done

dbs=`cat dbslist.txt`
echo  $dbs
hive -e "$dbs"
rm -f dbslist.txt
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值