Swapping the names of two databases

suggest change

The following commands swap two MySQL databases (db1 and db2) by copying them. Replace every <password>, <db1>, and <db2> before you run a line. A shell treats < as redirection. --routines does not include events; add --events when you need them. Account privileges are not copied.

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).

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents