Swapping the names of two databases
suggest changeThe 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:
- Copy the lines above into a text editor.
- Replace all references to
<db1>,<db2>and<password>(+ optionallyrootto use a different user) with the relevant values. - Execute one by one on the command line (assuming the MySQL “bin” folder is in the path and entering “y” when prompted).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents