开发者

How to rename database without deleting or moving tables in mysql? [duplicate]

This question already has answers here: Close开发者_开发技巧d 12 years ago.

Possible Duplicate:

How do I quickly rename a mysql database (change schema name)?

hi , plz help me to rename the database name in mysql


You should not use rename database as it will result in data loss http://dev.mysql.com/doc/refman/5.1/en/rename-database.html

Instead use alter database syntax http://dev.mysql.com/doc/refman/5.1/en/alter-database.html


You can choose any of the following ways to rename a database in MySQL.

If you have access to the directory where MySQL stores its databases. As per default MySQL installations, this is usually in the data directory under the directory where MySQL was installed. Locate the name of required database under the data directory and rename it as desired. Note: You must stop MySQL Server before renaming the database and may restart it after this operation. In this case, you may also grant permissions again on the renamed database. This only works for MyISAM tables. If you have tables with other storage engines than use the method described below.

Another way that seems safest, is to use mysqldump utility to back up the old database. Create a new database with desired name, then restore the dumped database under this database using the mysql utility. Finally, use the DROP DATABASE old_database_name; command to get rid of the old database. This is the safest method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜