修改mysql的數據庫名字

修改的原理就是創建一個新的數據庫然後把所有的表rename。具體就看下面的腳本吧。我是要把download這個數據庫的名字改成downloadv2

#!/bin/bash
mysql -uroot -p1q2w3e4r -e 'create database if not exists downloadv2'
list_table=$(mysql -uroot -p1q2w3e4r -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='download'")
for table in $list_table
do
mysql -uroot -p1q2w3e4r -e "rename table download.$table to downloadv2.$table"
done


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章