Monday, May 04, 2009

Renaming mysql database

Mysql version 5.1.7 to 5.1.23 had "RENAME TO ". It was later removed because of a finding that it can lead to data loss. The easiest way to achieve this now is to dump the contents of the existing database to another newly created one.

echo "create database new_database;" | mysql -u <username> -p <enter password>

mysqldump --user=<name> --password=<password> <old_database> | mysql -D new_database -p <enter password>

Now you can drop the old database ( after making sure you have all the contents on the new database). Ofcourse you need to recreate the user permissions for the new database.

No comments: