mysql數據庫改名


第一種:

RENAME database olddbname TO newdbname

這種方法官方不推薦,因為可能會造成數據丟失,所以不建議使用;

 

另一種:自己寫腳本實現

 1 #!/bin/bash
 2 mysql -uroot -e "create database if not exists db_ym_account"
 3 list_table=$(mysql -uroot -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='foundwant'")
 4 
 5 echo $list_table
 6 for tab in $list_table
 7 do
 8     echo "$tab"
 9     mysql -uroot -e "rename table foundwant.$tab to db_ym_account.$tab"
10 done

上面這里,我們想把db中foundwant的庫名改成db_ym_account;

第1行,創建db_ym_account庫;

第3行,把庫foundwant中的表記錄下來;

第9行,我們使用rename來操作table,這種方式就能把老庫中表中的數據轉移到新庫表中去;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM