hive表的建表语句批量获取

当hive中的一个数据库中有大量的表时,手动对表的建表语句备份就显得麻烦了,但是使用hive的命令和shell脚本会很容易实现。

1.导出所有表的名称(可以指定数据库名称)

hive -e "use dbName;show tables;" > tablesName.txt

2.使用hive内置语法导出hive表的建表语句,这里使用的是一个shell

#!/bin/bash 
cat /home/xiaohe/xiaohe_ni/tablesName.txt | while read tableName
do
hive -e "use dbName; show create table $tableName" >> tablesDDL.sql
done

猜你喜欢

转载自blog.csdn.net/u014236468/article/details/80928134