方法一
先删除表
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
本文介绍了两种在Hive中批量删除数据库的方法,包括先删除表再删除库的脚本操作方式以及直接的数据库级批量删除方法。
3191

被折叠的 条评论
为什么被折叠?



