修改的原理就是建立一個新的數據庫而後把全部的表rename。具體就看下面的腳本吧。我是要把download這個數據庫的名字改爲downloadv2mysql
#!/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