如何在 MySQL 中重命名架构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/490515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how does one rename a schema in MySQL
提问by Charles Faiga
Hi I am using mysql 5.0.x
嗨,我正在使用 mysql 5.0.x
How do I rename a schema?
如何重命名架构?
回答by pufferfish
Don't use RENAME DATABASE!!!
不要使用重命名数据库!!!
Early 5.1 versions had this command but it's been removed since it can corrupt data (reference).
早期的 5.1 版本有这个命令,但它已被删除,因为它会破坏数据(参考)。
The only way at present is
目前唯一的办法是
mysqladmin create new_db_name
mysqldump db_name | mysql new_db_name
as referred to here
如这里所指
Edit: Obviously this answer will become dated once this gets fixed.
编辑:显然,一旦解决这个问题,这个答案就会过时。
回答by OmegaOdie
It's easy. Export the database to file, then import it again in workbench you can specify the name of the db there.
这很简单。将数据库导出到文件,然后在工作台中再次导入,您可以在那里指定数据库的名称。
In workbench go to the Server tab, select Data Export. Select the DB you want to rename, select export to self contained file, and give the file a name. make sure you have Dump structure and Data selected. Hit start export.
在工作台中,转到服务器选项卡,选择数据导出。选择要重命名的数据库,选择导出到自包含文件,并为文件命名。确保您选择了转储结构和数据。点击开始导出。
In workbench go to the Server tab, select Data Import. Select Import from self contained file. Select the file you created. In the section titled Default Schema to be imported to click the new option. Enter the new name for the DB, then select it from the drop down. Hit Start Import.
在工作台中,转到服务器选项卡,选择数据导入。选择从自包含文件导入。选择您创建的文件。在标题为要导入的默认架构的部分中单击新选项。输入数据库的新名称,然后从下拉列表中选择它。点击开始导入。
Voila, new database with the name you want plus all the tables and data from the old one.
瞧,新数据库的名字是你想要的,加上旧数据库的所有表和数据。
回答by Grant Limberg
Under 5.0, you need to dump the database and reload it into a new database with a new name. If you upgrade to 5.1, you can lookup and use the RENAME DATABASE command.
在 5.0 下,您需要转储数据库并将其重新加载到具有新名称的新数据库中。如果升级到 5.1,则可以查找并使用 RENAME DATABASE 命令。