数据库重命名

 

 

#!/bin/bash
# 将testdb数据库名改为testdbbak
U=root
PWD=123456
mysql -u$U -p$PWD -e 'CREATE DATABASE if NOT EXISTS testdbbak'
list_table=$(mysql -u$U -p$PWD -Nse "SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA='testdb'")
for table in $list_table
do
    mysql -u$U -p$PWD -e "RENAME TABLE testdb.$table TO testdbbak.$table"
done

mysql -u$U -p$PWD -e "DROP  DATABASE testdb;"

 

posted @ 2022-03-24 13:53  papering  阅读(93)  评论(0编辑  收藏  举报