MySQL Swapping the names of two MySQL databases


Example

The following commands can be used to swap the names of two MySQL databases (<db1> and <db2>):

mysqladmin -uroot -p<password> create swaptemp
mysqldump -uroot -p<password> --routines <db1> | mysql -uroot -p<password> swaptemp
mysqladmin -uroot -p<password> drop <db1>
mysqladmin -uroot -p<password> create <db1>
mysqldump -uroot -p<password> --routines <db2> | mysql -uroot -p<password> <db1>
mysqladmin -uroot -p<password> drop <db2>
mysqladmin -uroot -p<password> create <db2>
mysqldump -uroot -p<password> --routines swaptemp | mysql -uroot -p<password> <db2>
mysqladmin -uroot -p<password> drop swaptemp

Steps:

  1. Copy the lines above into a text editor.
  2. Replace all references to <db1>, <db2> and <password> (+ optionally root to use a different user) with the relevant values.
  3. Execute one by one on the command line (assuming the MySQL "bin" folder is in the path and entering "y" when prompted).