带参数,手动指定数据库
#!/bin/bash
##批量获取hive建表HQL脚本
#输入数据库
DB=$1
#获取hive建表语句
tables=$(hive -e "use $DB; show tables;")
for table in $tables;
do
echo "--============ db: $DB , table: $table ============" >> /bak/hive_table_create.hql
echo "$(hive -e "use $DB;show create table $table;");" >> /bak/hive_table_create.hql
done
导入
#一个hql文件,直接执行即可
hive -f hive_table_create.hql
不带参数,自动获取全部库
#!/bin/bash
##获取数据库
databases=$(hive -e "show databases; exit;")
for database in $databases;
do
#获取hive建表语句
tables=$(hive -e "use $database; show tables;")
for table in $tables;
do
echo "--=========== db: $database , table: $table ==========="
echo "--=========== db: $dat