1、clear_hive_tables_by_database

  1. 描述:根据库名清空数据库下面的所有表 ```shell

    !/bin/bash

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};”

  1. # `sudo -u hive hive -e "truncate table ${dbName}.${table};"`
  2. done
  3. `sudo -u hive hive -e "${SQL}" -S`
  4. echo "数据库:${dbName}清空完毕!"
  5. echo "执行语句:${SQL}"

}

clear_database $1 ```