MySQL手册中有介绍。
通常我只是转储数据库并用一个新名称重新导入它。这不是非常大的数据库的一个选项。重命名数据库| SCHEMA} db_name TO new_db_name做坏事,只存在于少数版本中,总的来说是个坏主意。
这需要与InnoDB一起工作,InnoDB存储的东西与MyISAM非常不同。
MySQL手册中有介绍。
通常我只是转储数据库并用一个新名称重新导入它。这不是非常大的数据库的一个选项。重命名数据库| SCHEMA} db_name TO new_db_name做坏事,只存在于少数版本中,总的来说是个坏主意。
这需要与InnoDB一起工作,InnoDB存储的东西与MyISAM非常不同。
当前回答
我能给出的最快和最简单的解决办法是……在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.
使用以下几个简单的命令:
mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql
或者使用@Pablo Marin-Garcia建议的以下方法来减少I/O:
mysqladmin -u username -p create newdatabase
mysqldump -u username -v olddatabase -p | mysql -u username -p -D newdatabase
TodoInTX的存储过程不太适合我。以下是我的尝试:
-- stored procedure rename_db: Rename a database my means of table copying. -- Caveats: -- Will clobber any existing database with the same name as the 'new' database name. -- ONLY copies tables; stored procedures and other database objects are not copied. -- Tomer Altman (taltman@ai.sri.com) delimiter // DROP PROCEDURE IF EXISTS rename_db; CREATE PROCEDURE rename_db(IN old_db VARCHAR(100), IN new_db VARCHAR(100)) BEGIN DECLARE current_table VARCHAR(100); DECLARE done INT DEFAULT 0; DECLARE old_tables CURSOR FOR select table_name from information_schema.tables where table_schema = old_db; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET @output = CONCAT('DROP SCHEMA IF EXISTS ', new_db, ';'); PREPARE stmt FROM @output; EXECUTE stmt; SET @output = CONCAT('CREATE SCHEMA IF NOT EXISTS ', new_db, ';'); PREPARE stmt FROM @output; EXECUTE stmt; OPEN old_tables; REPEAT FETCH old_tables INTO current_table; IF NOT done THEN SET @output = CONCAT('alter table ', old_db, '.', current_table, ' rename ', new_db, '.', current_table, ';'); PREPARE stmt FROM @output; EXECUTE stmt; END IF; UNTIL done END REPEAT; CLOSE old_tables; END// delimiter ;
在phpmyadmin中,您可以轻松地重命名数据库
select database
goto operations tab
in that rename Database to :
type your new database name and click go
要求删除旧表和重新加载表数据单击确定
数据库被重命名
实际上,最简单的答案是导出旧数据库,然后将其导入到您创建的新数据库中以替换旧数据库。当然,您应该使用phpMyAdmin或命令行来做到这一点。
重命名和操纵数据库是一个坏主意!不要这样做。(除非你是那种“黑客类型”的人,在黑暗中坐在妈妈的地下室里,吃着披萨,白天睡觉。)
你最终会遇到比你想要的更多的问题和工作。
So,
Create a new_database and name it the correct way. Go to your phpMyAdmin and open the database you want to export. Export it (check the options, but you should be OK with the defaults. You will get a file like or similar to this. The extension on this file is .sql -- phpMyAdmin SQL Dump -- version 3.2.4 -- http://www.phpmyadmin.net -- Host: localhost -- Generation Time: Jun 30, 2010 at 12:17 PM -- Server version: 5.0.90 -- PHP Version: 5.2.6 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /; /!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /; /!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /; /!40101 SET NAMES utf8 */; -- -- Database: mydatab_online -- -- Table structure for table user CREATE TABLE IF NOT EXISTS user ( timestamp int(15) NOT NULL default '0', ip varchar(40) NOT NULL default '', file varchar(100) NOT NULL default '', PRIMARY KEY (timestamp), KEY ip (ip), KEY file (file) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table user INSERT INTO user (timestamp, ip, file) VALUES (1277911052, '999.236.177.116', ''), (1277911194, '999.236.177.116', '');
这将是您的.sql文件。你刚刚导出的那个。
在你的硬盘上找到它;通常在/temp中。选择具有正确名称(阅读本文的原因)的空数据库。 说:导入-开始
通过将程序输入到通常是configuration.php文件中,将程序连接到正确的数据库。刷新服务器(两个。为什么?因为我是UNIX老手,我说过。 现在,你的状态应该很好。如果你还有任何问题,请到网上来找我。