MySQL Rename Database

For security reasons the ability to rename a database was removed from later versions of MySQL. You can achieve the same goal using the methods below...

mysqldump

Follow the steps to duplicate the database, then drop the old database when you are done.

NOTE: Be sure to stop users/processes logging on to the database whilst performing these steps.

Rename Tables

innodb only

Create a new database, then rename all the tables in the old database to be in the new database...

RENAME TABLE myolddb.mytable TO mynewdb.mytable;

Remember to DROP the old database when you are done.

You can script this process to avoid the need to manually rename a lot of tables...

mysql -u myuser myolddb -sNe 'show tables' | while read table

do

mysql -u myuser -sNe "RENAME TABLE myolddb.$table TO mynewdb.$table"

done

s - silent modeN - suppress column namese - execute the statement that follows then quit
For the purposes of this script myuser will probably be 'root' (unless you have another user with enough privileges)
Use mysql_config_editor to avoid entering the password on the command line (and thus having it appear in the shell history)