#mysql數據庫改名,官方沒有直接修改數據庫名稱的命令
#只有通過修改表名方式實現
source /etc/profile #加載系統環境變量
source ~/.bash_profile #加載用戶環境變量
set -o nounset #引用未初始化變量時退出
mysqlconn="mysql -h localhost -uroot -p123456"
#需要修改的數據庫名
olddb="test1"
#修改后的數據庫名
newdb="test2"
#創建新數據庫
$mysqlconn -e "drop database if exists ${newdb};create database ${newdb};"
#獲取所有表名
tables=$($mysqlconn -N -e "select table_name from information_schema.tables where table_schema='${olddb}'")
#修改表名
for name in $tables;do
$mysqlconn -e "rename table ${olddb}.${name} to ${newdb}.${name}"
done
#刪除老的空庫
#$mysqlconn -e "drop database ${olddb}"
https://www.cnblogs.com/leffss/p/7832100.html
https://blog.csdn.net/gruhgd/article/details/84065218