MySQL手册中有介绍。

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

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


当前回答

如果你更喜欢GUI工具,并且碰巧安装了MySQL Workbench,你可以使用内置的迁移向导

其他回答

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.

简单的方法

切换到数据库目录:

cd /var/lib/mysql/

关闭MySQL…这很重要!

/etc/init.d/mysql stop

好吧,这种方法不适用于InnoDB或BDB-Databases。

重命名数据库:

mv old-name new-name

...或者桌子……

cd database/

mv old-name.frm new-name.frm

mv old-name.MYD new-name.MYD

mv old-name.MYI new-name.MYI

重新启动MySQL

/etc/init.d/mysql start

做……

好吧,这种方法不适用于InnoDB或BDB数据库。在这种情况下,您必须转储数据库并重新导入它。

I).没有办法直接改变现有数据库的名称 但你可以透过以下步骤达到目标:- 1).创建newdb。 2).使用newdb。 3). create table table_name(select * from olddb.table_name);

通过这样做,你复制数据从表的olddb和插入那些在newdb表。给表的名称相同。

II).重命名表old_db。table_name TO new_db.table_name;

在phpmyadmin中,您可以轻松地重命名数据库

select database 

  goto operations tab

  in that rename Database to :

  type your new database name and click go

要求删除旧表和重新加载表数据单击确定

数据库被重命名

我使用以下方法重命名数据库

使用mysqldump或任何数据库工具备份文件,如heidiSQL,mysql管理员等 在某些文本编辑器中打开备份(例如backupfile.sql)文件。 搜索并替换数据库名称并保存文件。

4.恢复已编辑的sql文件