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