I don't think you can do this. Basic answers will work in many cases, and in others cause data corruptions. A strategy needs to be chosen based on heuristic analysis of your database. 这就是这个特性被实现的原因,< a href = “ https://stackoverflow. com/questions/12190000/rename-mysql-database/21429268 # comments 21558791 _ 12190318”> 然后删除 。 [医生]
您需要转储 all object types in数据库,创建新命名的数据库,然后导入转储。如果这是一个活的系统,你需要把它关掉。如果不能,则需要设置从此数据库到新数据库的复制。
If you want to see the commands that could do this, @ satshD 有详细资料, which conveys some of the challenges around which you'll need to build a strategy that matches your target database.
mysql -e "CREATE DATABASE \`new_database\`;"
for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
mysql -e "DROP DATABASE \`old_database\`;"