1、clear_hive_tables_by_database
function clear_database(){
dbName=$1
tables=sudo -u hive hive -e "use ${dbName};show tables;" -S
SQL=””
echo “======数据库:${dbName}======”
for table in ${tables[@]};do
if [ ${table} == ‘WARN:’ ];then
break
fi
echo “正在执行数据表:${table}”
SQL=”${SQL}truncate table ${dbName}.${table};”
# `sudo -u hive hive -e "truncate table ${dbName}.${table};"`
done
`sudo -u hive hive -e "${SQL}" -S`
echo "数据库:${dbName}清空完毕!"
echo "执行语句:${SQL}"
}
clear_database $1 ```