lenmom

博客园 首页 新随笔 联系 订阅 管理

rename database hive to hive_cdh_1_1.

#!/bin/bash
#先判断新数据库是否存在,要是不存在就创建。
#列出老数据库下都有那些表,其中N和s参数起到的作用是格式化,有点类似于Oracle下sqlplus里的pagesize
#用for循环来rename。
echo 1
mysql -h 127.0.0.1 -uroot -proot -e 'create database if not exists hive_cdh_1_1'

echo 2
list_table=$(mysql -h 127.0.0.1 -uroot -proot -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='hive'")

for table in $list_table
do
    mysql -h 127.0.0.1 -uroot -proot -e "rename table hive.$table to hive_cdh_1_1.$table"
done

 

posted on 2019-07-08 17:04  老董  阅读(2710)  评论(0)    收藏  举报