MySQL手册中有介绍。

通常我只是转储数据库并用一个新名称重新导入它。这不是非常大的数据库的一个选项。重命名数据库| SCHEMA} db_name TO new_db_name做坏事,只存在于少数版本中,总的来说是个坏主意。

这需要与InnoDB一起工作,InnoDB存储的东西与MyISAM非常不同。


当前回答

在MySQL管理员中执行以下操作:

在Catalogs下,创建一个新的数据库模式。 转到备份并创建的备份 旧的模式。 执行备份。 转到恢复并打开文件 在步骤3中创建。 在目标下选择“另一个模式” 模式并选择新的数据库 模式。 开始恢复。 验证新模式,如果看起来 很好,删除旧的。

其他回答

I posted this How do I change the database name using MySQL? today after days of head scratching and hair pulling. The solution is quite simple export a schema to a .sql file and open the file and change the database/schema name in the sql CREAT TABLE section at the top. There are three instances or more and may not be at the top of the page if multible schemas are saved to the file. It is posible to edit the entire database this way but I expect that in large databases it could be quite a pain following all instances of a table property or index.

当您在PHPMyAdmin中重命名数据库时,它会创建一个转储,然后删除并使用新名称重新创建数据库。

MySQL目前不支持通过其命令界面重命名数据库,但如果您可以访问MySQL存储数据库的目录,则可以重命名数据库。对于默认的MySQL安装,它通常在MySQL安装目录下的Data目录中。在Data目录下找到要重命名的数据库的名称并重命名它。不过,重命名目录可能会导致一些权限问题。请注意。

注意:在重命名数据库之前,必须停止MySQL

我建议创建一个新数据库(使用您想要的名称),并将所需的数据从旧数据库导出/导入到新数据库。很简单。

在从包含多个数据库的转储文件开始的情况下,您可以对转储执行sed:

sed -i -- "s|old_name_database1|new_name_database1|g" my_dump.sql
sed -i -- "s|old_name_database2|new_name_database2|g" my_dump.sql
...

然后导入您的转储。只要确保没有名称冲突即可。

对于那些Mac用户,Sequel Pro在数据库菜单中有一个重命名数据库选项。 http://www.sequelpro.com/