MySQL Copy Table from One Database to Another
Monday, March 3rd, 2008Sometime in MySQL you want to copy an entire table from one database to a separate database. One example of when you would want to do this is if you are making a backup of a table before you apply some kind of processing to that table. There is nothing worse than ruining a database table and losing valuable information. To make an instant backup is so easy that there really is no excuse not to make backups at important or risky stages.
Here is how to do it:
-
DROP TABLE IF EXISTS `backup_db.backup_table`;
-
CREATE TABLE `backup_db.backup_table` SELECT * FROM `live_db.live_table`;
This will delete your existing backup table completely, then will remake it copying all structural information and content from the live_table in the live_db.
Related Blogs
http://www.phpclasses.org/browse/package/4017.html
http://www.sematopia.com/?p=61
http://www.yinfor.com/blog/archives/2008/02/mysql_backup_and_recovery_meth.html
