MySQL efficiently copy all records from one table to another

前端 未结 4 1413
栀梦
栀梦 2021-01-01 15:47

Is there a more-efficent, less laborious way of copying all records from one table to another that doing this:

INSERT INTO product_backup SELECT * FROM produ         


        
4条回答
  •  迷失自我
    2021-01-01 15:58

    I don't think this will be worthy for a 50k table but: If you have the database dump you can reload a table from it. As you want to load a table in another one you could change the table name in the dump with a sed command: Here you have some hints: http://blog.tsheets.com/2008/tips-tricks/mysql-restoring-a-single-table-from-a-huge-mysqldump-file.html

    An alternative (depending on your design) would be to use triggers on the original table inserts so that the duplicated table gets the data as well.

    And a better alternative would be to create another MySQL instance and either run it in a master-slave configuration or in a daily dump master/load slave fashion.

提交回复
热议问题